Razor how to list nodes with a certain property (where that property can have multiple values)
I'm trying to create a macro to list descendants of a
particular document type where a property equals a certain value (in this
instance the property is ‘scholarship’).
The property field for ‘scholarship’ in the document type uses
an ‘ultimate picker’ and can have more than one option selected.
I have created other similar macros (using different
properties) that have worked where the particular property has used a drop-down
list or a text field where only one option is entered for each so I’m guessing
that is where the problem is but I’m not sure. The other difference is the property
field in this instance uses ‘ultimate picker’ rather than a list.
This is the what I have at the moment which doesn’t produce
a list:
@using umbraco.MacroEngines @inherits DynamicNodeContext @{ string scholarshipToFind = Parameter.ProgrammeScholarship; var root =Model.AncestorOrSelf(1); var programmeNames = root.DescendantsOrSelf("Programme").OrderBy("programmeName").ToList();
Hi thanks again but still the same, I changed the alias of the parameter to programmeScholarship and changed this in the .cshtml file but still the same result
Razor how to list nodes with a certain property (where that property can have multiple values)
I'm trying to create a macro to list descendants of a particular document type where a property equals a certain value (in this instance the property is ‘scholarship’).
The property field for ‘scholarship’ in the document type uses an ‘ultimate picker’ and can have more than one option selected.
I have created other similar macros (using different properties) that have worked where the particular property has used a drop-down list or a text field where only one option is entered for each so I’m guessing that is where the problem is but I’m not sure. The other difference is the property field in this instance uses ‘ultimate picker’ rather than a list.
This is the what I have at the moment which doesn’t produce a list:
Hi Clare,
I would approach this by using a handy Razor helper, something like this:
Hope that's helpful,
Jeavon
Thanks Jeavon, I tried that but I get an error message when I insert the macro into a page (Error loading MacroEngine script)
Hi Clare,
Ok, lets add a try/catch so we can see what the error is:
Also the @functions section should be the very last thing in your .cshtml file
Jeavon
Thanks Jeavon, trying that I get the following error:
Object reference not set to an instance of an object.
Is there any other info or only that?
When I place the macro on a page that's all I get where the macro is
Hmm, I wonder if there is a problem with the alias of your parameter?
Maybe it should be
Parameter.programmeScholarship
?Hi thanks again but still the same, I changed the alias of the parameter to programmeScholarship and changed this in the .cshtml file but still the same result
Strange, seems to work perfectly for me.
Could you please post your entire .cshtml contents?
Ah wait, try updating the function like this (it wasn't checking for no selection in the picker)
I've updated the function now which has removed the error message but I still don't get anything in my list.
This is now the content of my .cshtml file:
It's working now! Sorry it only just clicked that for the macro property I needed to enter the ID of the page rather than the value.
Thank you so much for your help
That's great! It's a really tidy way to handle this type of common requirement to filter based on CSV pickers like Ultimate and Multinode pickers.
is working on a reply...