Question

I am setting up a new Umbraco site - this is the first time I have used Umbraco and was wondering how to get the generic properties for the node back as the type I set them as.

For example, I have created a generic property of includeSubNav which I have set to a type of true/false. To access this property I am calling

Node.GetCurrent().getProperty("includeSubNav").Value

My question is, is this the correct way to get the property? If so why is the .Value always returned as a string as in this instance a "1" isn't very helpful as I can't parse this as a boolean, which means I have to use an if statement to see if it is "1" which I just find quite dirty

Was it helpful?

Solution

Because Umbraco is using an XML file which contains the complete content tree (for speed purpose), all values are converted to strings. When you read data from Node, you are using the NodeFactory which uses the XML file.

The GetProperty method is the correct way to read properties and indeed returns all values as string and in case of a boolean, you need to use a .Equals("1") function or convert it to a Bool.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top