How can we access document type properties directly on Master.cshtml?
This is probably a simple no answer, but I'm curious anyway....
Under Settings in Backoffice, I created a document type called 'Site Settings'. It is not tied to a template. I have several properties applied to it. Is it possible to access properties directly on Master.cshtml?
For example, I would like to do something like this directly on Master.cshtml...
if (Model.HasValue("globalHeadScripts"))
{
<script>
@Html.Raw(Model.GlobalHeadScripts);
</script>
}
globalHeadScripts is a property on my Site Settings document type. Is this process possible?
My end goal is to do something like this....
+ My site: (this root node is tied to a document type called 'My Site', which is inheriting a composition called 'Site Settings'. I want Master.cshtml to access 'Site Settings' properties. )
+ Home: (child content node of My Site. I will modify its 'Cultures and Hostnames' to be available as the default site when Umbraco loads.)
+ About:
+ Contact us
+ etc....
@{
@*The global script for all pages.*@
var settingsNode = Umbraco.TypedContent(1080);
if (settingsNode.HasProperty("globalHeadScripts") && settingsNode.HasValue("globalHeadScripts"))
{
<script>
@Html.Raw(settingsNode.GetPropertyValue("globalHeadScripts"));
</script>
}
}
...But I'm getting an error...
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
There are no errors when I build my project out of visual studio.
My using statements at the top of my page looks like this...
I see what I was doing wrong.. I was trying to get the document ID into Umbraco.TypedContent(), when I should of been referencing an id from the content node that is using 'Site Settings' All is good now!
How can we access document type properties directly on Master.cshtml?
This is probably a simple no answer, but I'm curious anyway....
Under Settings in Backoffice, I created a document type called 'Site Settings'. It is not tied to a template. I have several properties applied to it. Is it possible to access properties directly on Master.cshtml?
For example, I would like to do something like this directly on Master.cshtml...
globalHeadScripts is a property on my Site Settings document type. Is this process possible?
My end goal is to do something like this....
Thanks!
Hi Blackhawk
Yes, it's possible
You have to get Settings node and then something like that:
Hey
Probably should also include "HasProperty" before checking for a value.
Cheers
Nigel
I'm doing the following...
...But I'm getting an error...
There are no errors when I build my project out of visual studio.
My using statements at the top of my page looks like this...
and my document type looks like this...
If debugging, do you get a node object when setting settingsNode ?
I see what I was doing wrong.. I was trying to get the document ID into Umbraco.TypedContent(), when I should of been referencing an id from the content node that is using 'Site Settings' All is good now!
Many many thanks!
is working on a reply...