Copied to clipboard

Flag this post as spam?

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


  • Joao 53 posts 172 karma points
    Mar 20, 2013 @ 15:11
    Joao
    0

    Trouble accessing properties of a node

    Hello!

    I have this macro that is working as intended:

    <umbraco:Macro runat="server" language="cshtml">
    @using umbraco.MacroEngines;
    <ul>
     @{
    DynamicNode contentRoot = new DynamicNode(-1);
    foreach (DynamicNode n in contentRoot.Descendants("SpeciesNameSimple")){
    <li><a href="@n.Url">@n.Name</a></li>
       }
    }
      </ul>
    </umbraco:Macro>

    It lists all the nodes perfectly with working urls. I would like to also access a custom property I created in the doc type with the alias speciesHighlightText. For that I added the following:

    <umbraco:Macro runat="server" language="cshtml">
    @using umbraco.MacroEngines;
    <ul>
     @{
    DynamicNode contentRoot = new DynamicNode(-1);
    foreach (DynamicNode n in contentRoot.Descendants("SpeciesNameSimple")){
    <li><a href="@n.Url">@n.Name</a></li>
    <li>@n. speciesHighlightText </li>
    }
    }
      </ul>
    </umbraco:Macro>

    When I run the page the macro fails to load. What am I missing here?

  • gary 385 posts 916 karma points
    Mar 20, 2013 @ 16:21
    gary
    0

    Hi João

    Are you using 4.8+ ? or v6?

    If so,

    <li><a href=n.Url">n.Name</a></li>

    <li>n.SpeciesHighlightText</li> 

    should work, could be the @ inside the code block that is breaking it in Razor V2.

    Hope it helps

    G

  • Joao 53 posts 172 karma points
    Mar 20, 2013 @ 17:55
    Joao
    0

    I'm using umbraco v 4.11.3. If i put <li>n.speciesHighlightText</li> i get as a result the text: n.speciesHighlightText

  • gary 385 posts 916 karma points
    Mar 20, 2013 @ 18:13
    gary
    0

    Apologies João,

    My error, was looking at the code block on the left, did not read the foreach loop correctly.

    <li><a [email protected]">@n.Name</a></li>

    <li>@n.SpeciesHighlightText</li>

    The alias needs the capital at the front, so Species, not species . . .

    Hope it is better this time

    G

     

     

     

  • Joao 53 posts 172 karma points
    Mar 20, 2013 @ 19:13
    Joao
    0

    It does not work with <li>@n.SpeciesHighlightText</li> and when i tried to change the alias name from speciesHighlightText to SpeciesHighlightText Umbraco does not let me do it an mantains the lower case letter

  • Wouter Dewispelaere 5 posts 47 karma points
    Mar 21, 2013 @ 21:39
    Wouter Dewispelaere
    100

    Hi João;

    you could use the GetProperty method to access the property.

    So in your case <li>@n.GetProperty("speciesHighlightText").Value </li> should do the trick.

    Take care,

    WD


  • Joao 53 posts 172 karma points
    Mar 22, 2013 @ 14:53
    Joao
    0

    It worked! Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft