What is the best way to get values from other nodes in Umbraco? I want to use this to query general settings on my website. I have a dedicated node in my content tree where all settings are. I've tried using this:
var settings = Umbraco.Content(2017)
This returns an "Umbraco.Web.PublishedModels.Homepage" object as expected. When I want to pick some values from this model, it won't let me. For example, I want to do this:
@settings.WebsiteName
This returns an error stating "'IPublishedContent' does not contain a definition for 'WebsiteName'". It does work when I add the Value method:
@settings.Value("websiteName")
This works for a textbox field, but not for other properties like nested content or a link property.
Does anyone know how to correctly query these properties as well? Thanks in advance!
Thanks for your answer. Yes, I think we are using the Models Builder, our configuration looks like this:
Though I can't use the Models Builder like I would in let's say a partial view (Model.WebsiteName e.g.). It returns an: "'IPublishedContent' does not contain a definition for 'WebsiteName'".
I've both tried it on my master template and in a partial view, both result in these errors.
Get value from other node with Umbraco helper
Hi there,
What is the best way to get values from other nodes in Umbraco? I want to use this to query general settings on my website. I have a dedicated node in my content tree where all settings are. I've tried using this:
This returns an "Umbraco.Web.PublishedModels.Homepage" object as expected. When I want to pick some values from this model, it won't let me. For example, I want to do this:
This returns an error stating "'IPublishedContent' does not contain a definition for 'WebsiteName'". It does work when I add the Value method:
This works for a textbox field, but not for other properties like nested content or a link property.
Does anyone know how to correctly query these properties as well? Thanks in advance!
Are you using Models Builder?
A property of type "nestedcontent" will return a list of nodes, which you will need to iterate through.
Read through the relevant Umbraco documention to see how each property is returned, and how best to handle.
Thanks for your answer. Yes, I think we are using the Models Builder, our configuration looks like this:
Though I can't use the Models Builder like I would in let's say a partial view (Model.WebsiteName e.g.). It returns an: "'IPublishedContent' does not contain a definition for 'WebsiteName'".
I've both tried it on my master template and in a partial view, both result in these errors.
Try something like
I think the "content" method just returns a dynamic type.
The "P" on HomePage might not be captilized in your project - Depends how you spelt "homepage" or "home page" :)
You could do this as well, which might be more efficient, and doesnt rely on hardcoding the ID
is working on a reply...