Copied to clipboard

Flag this post as spam?

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


  • John C Scott 457 posts 1157 karma points
    Jun 20, 2011 @ 16:51
    John C Scott
    0

    passing @id to XSLT macro

    rt @johncscott #umbraco a way to pass the ID of the current page to a .net user control using advanced parameter syntax EG: <umbraco:Macro CrewId="[#id]".?

    what on earth does that all mean!? :)

    i have a template which is showing an xslt macro

    and passing parameters to the page using advanced parameter syntax

            <umbraco:Macro MealId="1" CrewId="[#id]" Alias="[uc]TakenButton" runat="server"></umbraco:Macro>

    so if a property of the document were crewMealId i can write

            <umbraco:Macro MealId="1" CrewId="[#crewMealId]" Alias="[uc]TakenButton" runat="server"></umbraco:Macro>

    and this is read correctly by the .net User Control ASCX 

    however if I would like to pass the node id of the current page being viewed in the template, an equivalent of $currentPage/@id

    What is the best way to do this?

     



     

  • Keith Jackson 183 posts 552 karma points
    Jun 20, 2011 @ 16:59
    Keith Jackson
    1

    I'm sure I did this last week - I'm just checking through my POC files.

    Is it not something like <umbraco:Macro PageId="[$currentPage]" Alias="[uc]Test" runat="server"></umbraco:Macro>

    I'll get back to you in 15

  • John C Scott 457 posts 1157 karma points
    Jun 20, 2011 @ 17:15
    John C Scott
    0

    thanks Keith

  • Keith Jackson 183 posts 552 karma points
    Jun 20, 2011 @ 17:47
    Keith Jackson
    0

    I failed to get this working through the parameter so I wrote this code to set the parameter to the current page ID in the event that the parameter value was empty instead.

     

    using System;

     

    namespace Umbraco_User_Controls.usercontrols

    {

        public partial class PageID : System.Web.UI.UserControl

        {

            protected void Page_Load(object sender, EventArgs e)

            {

                if (String.IsNullOrEmpty(CurrentPageID))

                {

                    CurrentPageID = umbraco.NodeFactory.Node.getCurrentNodeId().ToString();

                }

            }

     

            public string CurrentPageID { get; set; }

        }

    }

  • John C Scott 457 posts 1157 karma points
    Jun 20, 2011 @ 18:48
    John C Scott
    0

    i get an error

    'umbraco.presentation.nodeFactory.Node' does not contain a definition for 'getCurrentNodeId'

    any ideas?
    which version of CMS are you using?

     

     

  • John C Scott 457 posts 1157 karma points
    Jun 20, 2011 @ 19:01
    John C Scott
    0

    NO NO :D sorted

    all very good

    thank you that works a treat

     

    TOP RESPECT TO KEITH 

    thank you again :)

  • Anthony Dang 1404 posts 2558 karma points MVP 2x c-trib
    Jun 20, 2011 @ 19:03
    Anthony Dang
    0

    You can just do this on page load:

    Item item = new Item();
    int pageId = int.Parse(item.PageElements["pageID"].ToString());

    make sure you include: using umbraco.presentation.templateControls;

    Works every time.

     

  • 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