Iterating over items from DynamicXml - Related Links Data
Hi All,
Im trying to use razor to iterate over a field of RelatedLinks against my homepage node. I can see the field is returned in razor as DynamicXml and therefore believe I should be able to use dot notation to access and itterate over the contents (from the razor feature walkghtoughs). When I use '.links' to jump into the first element of the xml, I receive 'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'links'. Here is my code:
.. So im led to believe I can do this: *@ <br /> @foreach(var l in homepage.siteLinksFirstSet.links) { @l.title } @* .. but im getting
'umbraco.MacroEngines.DynamicXml' does not contain a definition for
'links' :( *@
It will skip the first "links" node because that is used as the root of your XML. So just do a foreach on homepage.siteLinksFirstSet and you should be good to go!
Ps. a similar example is in my Razor examples project (on the uComponents page), it adds some checks in case you leave it empty. You might need to check if there's only 1 link in there as well, not sure how that would be handled.
Iterating over items from DynamicXml - Related Links Data
Hi All,
Im trying to use razor to iterate over a field of RelatedLinks against my homepage node. I can see the field is returned in razor as DynamicXml and therefore believe I should be able to use dot notation to access and itterate over the contents (from the razor feature walkghtoughs). When I use '.links' to jump into the first element of the xml, I receive 'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'links'. Here is my code:
It will skip the first "links" node because that is used as the root of your XML. So just do a foreach on homepage.siteLinksFirstSet and you should be good to go!
Ps. a similar example is in my Razor examples project (on the uComponents page), it adds some checks in case you leave it empty. You might need to check if there's only 1 link in there as well, not sure how that would be handled.
Thanks Seb! That was it!
Taken your HasProperty and HasValue examples.
When only 1 item is in the array - it continues to work fine :)
is working on a reply...