In umbraco, is it possible to check if certain property exist for particular node?
For example, I am having 5 nodes and I am having media picker property for first node alone. I need to check all the nodes whether media picker property is available for nodes or not?
check property existence
Are you doing this in an xslt file or in a user control? –
Haphazard
I think you can just check property existence by comparing to null:
Node somenode = new Node(myNodeID);
if (somenode.GetProperty("myProperty") != null)
{
string myProperty = somenode.GetProperty("myProperty").Value.ToString();
//Do something with myProperty
}
If you are using Razor you can do it like this:
Model.HasProperty("MyPropertyAlias")
And you can check if the property contains a value as follows:
Model.HasValue("MyPropertyAlias")
you can do like this
if (Model.Content.HasValue("alias"))
{
//placeyour code here
}
You should first check that the property exists before checking for a value or I think you will get a null reference exception if for some reason it doesn't exist. –
Lonilonier
© 2022 - 2024 — McMap. All rights reserved.