Copied to clipboard

Flag this post as spam?

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


  • Stephen 204 posts 246 karma points
    Nov 02, 2011 @ 20:31
    Stephen
    0

    Get page ID of current section

    I have a razor script which will display members names based on a parameter (i.e sectionID).  The user can insert the script and specify the section via the node tree. 

    I want to use it a little differently by using the script in a template and would like to pick up the secitonID based on the current seciton the user is in...so i guess my question is how to I pass the sectionID to the script when the page loads?

    Cheers,

    S

  • Anthony pj 40 posts 63 karma points
    Nov 02, 2011 @ 23:40
    Anthony pj
    0

    Assuming that is SectionId was a propertry of the page you were on you would know know to extract it ... here is soem razor that navigates back up the tree and find the first parent with the property sectionId

    @foreach (var item in Model.AncestorOrSelf(1).Children.Where("Visible" )) {
        
          if(Model.IsDescendantOrSelf(item) )
          {
          if(item.sectionId.GetType() != typeof(DynamicNull))
             {
               @item.Name
              }                                                       

    }

    alternatively you could check for the prpoerty by using

    if(item.HasProperty("sectionName")){
          @item.Id
         }
                  

  • Anthony pj 40 posts 63 karma points
    Nov 02, 2011 @ 23:51
    Anthony pj
    0

    Opps on rereading your post I thing i may have misunderstood what you were gettting at ............ maybe this more what you are after

    http://our.umbraco.org/forum/developers/razor/19040-Working-with-members-and-Razor

  • Stephen 204 posts 246 karma points
    Nov 03, 2011 @ 08:52
    Stephen
    0

    no worries it’s the way a write them, confusing!

    Essentially all I need to know is how to pass a parameter into a macro and ensure the parameter the page id on the page that the macro is currently on...

     

  • Stephen 204 posts 246 karma points
    Nov 03, 2011 @ 11:58
    Stephen
    0

    Incase anyone wants to know it turned out to be really simple!

    <umbraco:Macro ServiceType="[#pageID]" Alias="tmStaffSimple" runat="server"></umbraco:Macro>


    Can i mark this as the answer?

    S

  • Anthony pj 40 posts 63 karma points
    Nov 03, 2011 @ 11:58
    Anthony pj
    0

    do you simply mean

    @Model.Id   where thsi returns the page Node Id of the current page ?

  • Anthony pj 40 posts 63 karma points
    Nov 03, 2011 @ 12:01
    Anthony pj
    0

    Not Sure why you want to pass the PageId or any other page property when you can read them directly from your razor script? 

  • Stephen 204 posts 246 karma points
    Nov 03, 2011 @ 15:03
    Stephen
    0

    Sorry Anthony, I am in fact using a user control and not a razor script, head is firmly up my arse!  All working the way i want to now.

    Thanks for your input.

    S

  • Anthony pj 40 posts 63 karma points
    Nov 03, 2011 @ 15:39
    Anthony pj
    0

    To read page properties direct in a usercontrol without passing you can do the following

    using umbraco.BusinessLogic;
    using umbraco.cms.businesslogic.web;
    using umbraco.NodeFactory ;

    protected void Page_Load(object sender, EventArgs e)
            {
               _nameLabel.Text = GetPropertyFromAlias("contactNameLabel");
            }

    private static string GetPropertyFromAlias(string alias)
            {
                return Node.GetCurrent().GetProperty(alias) != null
                    ? Node.GetCurrent().GetProperty(alias).Value
                    : string.Empty;
            }

    I am sure you get the idea from the snippets above

    These are taken out Sebastiaan Janssen contact form http://our.umbraco.org/projects/website-utilities/cultiv-legacy-contact-form-(pre-47!)

Please Sign in or register to post replies

Write your reply to:

Draft