Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi Guys
I'm trying to list a selection of nodes, that has a certain property = true.
As an example I want to list all the sales-departments that sells a specific product.
On @Model i have a Text-string in which i type the exact name of the child.property I want to be true for my list
So far I've gotten this:
@inherits umbraco.MacroEngines.DynamicNodeContext@{ var Department = @Model.findDep; var parent = @Model.NodeById(1095); if (parent != null) { <ul id="find-dep"> @foreach (var item in parent.Children.Where("Visible")) { if(item.Department) { <li id=@item.Company> <a href="@item.Url"><em>@item.Name</em></a> </li> } } </ul> }}
The @Department returns the correct text-string, but the If-sentence returns nothing.
How can I use the "Department"-variable as the property-field I want to check. If I hardcode the variable-text the if-sentence works.
I hope somebody can help me :-)
Hi,
So @Model.findDep contains the property alias that you want to check is true or false?
You could try changing your if statement to:
if (item.GetPropertyValue(Department) == "1")
That should work. Note GetPropertyValue returns a string so you need to check that way.
But it would probably be best if you could do this in your foreach loop, I think this should work:
@foreach (var item in parent.Children.Where("Visible && " + Department))
This should be the same as writing "Visible && yourPropertyAlias"
Hope this helps,Tom
Both things work :-) I took the @foreach solution, as I then didn't need an if-sentence :-)
Thank you very much :-)Jimmy
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Children of note that has a specific property = true
Hi Guys
I'm trying to list a selection of nodes, that has a certain property = true.
As an example I want to list all the sales-departments that sells a specific product.
On @Model i have a Text-string in which i type the exact name of the child.property I want to be true for my list
So far I've gotten this:
The @Department returns the correct text-string, but the If-sentence returns nothing.
How can I use the "Department"-variable as the property-field I want to check. If I hardcode the variable-text the if-sentence works.
I hope somebody can help me :-)
Hi,
So @Model.findDep contains the property alias that you want to check is true or false?
You could try changing your if statement to:
That should work. Note GetPropertyValue returns a string so you need to check that way.
But it would probably be best if you could do this in your foreach loop, I think this should work:
This should be the same as writing "Visible && yourPropertyAlias"
Hope this helps,
Tom
Both things work :-) I took the @foreach solution, as I then didn't need an if-sentence :-)
Thank you very much :-)
Jimmy
is working on a reply...