Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simon 17 posts 37 karma points
    Sep 23, 2011 @ 18:28
    Simon
    0

    How to pass the template ID to a Macro?

    Hi,

    I'm pretty new to Umbraco and need to know the best way of doing something

    I have a macro on a template which calls a .ascx file. I currently pass the PageID which I then use in the .ascx file to return a specific phone number for a specific page.

    I'd now like to extend this to be able to display a specific phone number on each page that use a specific Template.

    I can get the template ID like this: <umbraco:Item runat="server" field="template"/> but I don't know how to pass that value to my macro.

    This is the macro tag I'm currently using:

     <umbraco:Macro PageID="[#pageID]"  Alias="ControlName" runat="server"></umbraco:Macro>

    Any help would be greatly appreciated.

     

    Thanks

    Simon

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Sep 23, 2011 @ 21:07
    Bo Damgaard Mortensen
    0

    Hi Simon,

    I'm not sure how to achieve just that, but can't you just fetch the current pages template id from within your UserControl? Like this:

    Node currentNode = Node.GetCurrent();
    Template template = new Template(currentNode.Id); 

    ? :-)

    All the best,

    Bo

  • Simon 17 posts 37 karma points
    Sep 26, 2011 @ 13:23
    Simon
    0

    Hi Bo,

    Thanks for your reply.

    And thanks for getting me on the right track!

    Template template = new Template(currentNode.Id);

    returned an object not set to an instance of an object error. But, 

    Node currentNode = Node.GetCurrent();
    var template = currentNode.template;

    Returned the id of the current template.

    Would this be caused by a difference in versions? I'm using 4.5.2.

    Thanks again for you help.

    Simon

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies