Copied to clipboard

Flag this post as spam?

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


  • Bex 444 posts 555 karma points
    Oct 25, 2010 @ 18:27
    Bex
    0

    How do you pass the pageID to a macro?

    Hello!

    I am trying to pass the page ID to my usercontrol macro.

    I have tried the following:

     

    <umbraco:Macro ID="Macro1" CurrentMediaId='[#PageId]' Alias="Comments" runat="server"></umbraco:Macro>

    <umbraco:Macro ID="Macro1" CurrentMediaId='<umbraco:Item field="pageID" runat="server"></umbraco:Item>
    ' Alias="Comments" runat="server"></umbraco:Macro>
    My parameter CurrentMediaId is an Int
    Both these ways pass either null or the string value.. what am I doing wrong?
    Please help!
    Bex

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Oct 25, 2010 @ 18:36
    Kim Andersen
    0

    Hi Bex

    You should be able to pass the current pages id like this:

    <umbraco:Macro ID="Macro1" CurrentMediaId='[#pageID]' Alias="Comments" runat="server"></umbraco:Macro>

    Almost like you already did, but with a lower 'p'.

    /Kim A

  • Bex 444 posts 555 karma points
    Oct 25, 2010 @ 18:40
    Bex
    0

    Arrrrrrrrrrrrrrrrrrrrrgh!!

    Lower case P!! that's the problem! Working now! Just worked it out as you posted!

  • Kim Andersen 1447 posts 2196 karma points MVP
    Oct 25, 2010 @ 18:46
    Kim Andersen
    0

    Great ;)

    In your c# you can also get the current page's id through the nodeFactory. There's a small guide in the Wiki about it: http://our.umbraco.org/wiki/reference/api-cheatsheet/working-with-the-nodefactory

    If you look in the bottom part of the article you'll see how to get the name, a property etc. And if you want to grab the id you can simply do like this:

    Node currenNode = Node.GetCurrent();
    int id = currenNode.Id;

    That way you don't have to worry about sending the as a param through the macro. But that's up to you :)

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft