<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?
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
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?
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
I'm using umbraco v 4.11.3. If i put <li>n.speciesHighlightText</li> i get as a result the text: n.speciesHighlightText
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
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
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
It worked! Thanks!
is working on a reply...