and my razor script shows this error: 'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'value' (because there aren't any value nodes).
First of all, make sure you're using a recent version of the 4.7.1 macro engine, grab a recent nightly and copy the umbraco.MacroEngines.dll over to your bin folder.
Then it should be fairly easy, here's an extra safe sample (it checks is the TextRotator property actually exists, and if it's not empty AND if the count of values is more than 0):
hi Sebastiaan, would your code work if there was only one item in that rotator?
i've discovered a problem with our use of dynamicNode and ucomponents multinode picker XML:
@foreach (var x in Model.featureHeaderPromos.nodeId)
if the xml only has one node then its dynamically resolved to one string rather than a collection of node strings. This means that the loop will iterate over the string i.e. the chars that make up the string.
We've added another couple of overloads to MediaById and NodeById
that take List<object> and params object[]
These let you return multiple nodes as a list.
The intention for these methods is to give better support when
working with the uComponents multi node tree picker.
MediaById returns a new type, DynamicMediaList
var nodes = @Model.NodeById(Model.multiChildPicker);
@andrew in your first snippet, remove NodeId from the foreach..
Something like this works fine:
@if (Model.GetPropertyValue("UcMultiNodeTreePicker") != string.Empty && Model.UcMultiNodeTreePicker.Count() != 0)
{
<ul>
@foreach (var nodeId in Model.UcMultiNodeTreePicker)
{
@* The nodeId is an XML node of which we need to get the text to get the real ID *@
var contentItem = Model.NodeById(nodeId.InnerText);
<li>@contentItem.Name</li>
}
</ul>
}
The second sample doesn't work for me either and I don't see why it would be useful, the method is called NodeById, not NodesById (with an s), so I would expect only one node to be returned, not multiple (and therefore, you'd also only put one nodeId in it).
Refer to the above example though, to loop through 1 or multiple nodes.
@sebastiaan, thanks for that example, i had something every similar in my original code but i found that if theres only one item selected in the multinode picker then Model seems to change the type being returned from a collection of strings to a single string. this means it tries to loop through the chars of the string rather than the collection of string values.
can you let me know how you get on with one item selected in your picker? thanks
@Murray That was what the test for != string.Empty is for, however, I could've expressed that better with Model.HasValue("TextRotator").
Here is an ULTRA safe version, which also first tests if any of the nodes that have been picked (if any) are actually published. In reality, it's unlikely that you'll need to go to that extreme:
Testing existance of children
Hi it seems it is ver difficult to easly test that child properties exist in DynamicNode DynamicXml
I have this code:
I have this XML:
and my razor script shows this error: 'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'value' (because there aren't any value nodes).
How do I test for this?
I use those two functions:
I have a blog where I put those kinds of things: http://whatis.goingle.me/dynamicxml-propertyhasvalue-implementation-um.
Does this help?
First of all, make sure you're using a recent version of the 4.7.1 macro engine, grab a recent nightly and copy the umbraco.MacroEngines.dll over to your bin folder.
Then it should be fairly easy, here's an extra safe sample (it checks is the TextRotator property actually exists, and if it's not empty AND if the count of values is more than 0):
hi Sebastiaan, would your code work if there was only one item in that rotator?
i've discovered a problem with our use of dynamicNode and ucomponents multinode picker XML:
if the xml only has one node then its dynamically resolved to one string rather than a collection of node strings. This means that the loop will iterate over the string i.e. the chars that make up the string.
Gareth Evans mentions the use of multinode pickers in part 5 of this razor article:
http://umbraco.com/follow-us/blog-archive/2011/3/13/umbraco-razor-feature-walkthrough-part-5.aspx/
var nodes = @Model.NodeById(Model.multiChildPicker);
that doesn't seem to work for me.
@andrew in your first snippet, remove NodeId from the foreach..
Something like this works fine:
The second sample doesn't work for me either and I don't see why it would be useful, the method is called NodeById, not NodesById (with an s), so I would expect only one node to be returned, not multiple (and therefore, you'd also only put one nodeId in it).
Refer to the above example though, to loop through 1 or multiple nodes.
@sebastiaan, thanks for that example, i had something every similar in my original code but i found that if theres only one item selected in the multinode picker then Model seems to change the type being returned from a collection of strings to a single string. this means it tries to loop through the chars of the string rather than the collection of string values.
can you let me know how you get on with one item selected in your picker? thanks
That code works perfectly with one item, which is why I added it ;-)
Remember though, that I'm using the most recent nightly version of umbraco.MacroEngines.dll, can't speak for the 4.7.0 release or interim builds.
yep, i had updated to the latest 4.7.1 build assembly. strange that it didn't work for me.
Make sure not to include the .nodeId in the foreach is all I can think of! Try again adapting the sample code above, would love to know if that helps!
@Sebastiaan, your example is not checking the nodes are published.
In your example that check would need to be added to the first line to ensure the ul is not output if there are no published nodes.
@Murray That was what the test for != string.Empty is for, however, I could've expressed that better with Model.HasValue("TextRotator").
Here is an ULTRA safe version, which also first tests if any of the nodes that have been picked (if any) are actually published. In reality, it's unlikely that you'll need to go to that extreme:
i have some code to convert the contents of a multinodepicker property into a list of published nodes here:
http://our.umbraco.org/forum/developers/razor/24098-dynamic-and-razor-@functions
any help converting this working code into a @function would be appreciated.
thanks
is working on a reply...