Access Umbraco published content from .master page.
Hi,
This is may be a basic question, can anyone help please, I am unable to get properties of template from .master page. I have a content node which uses template (.master page) , I would need to access two properties in master page (document type contains 2 properties to which content node is pointing) please find the sample attached below. I dont want to hardcode the node id, hence would like to get it dynamically. In below example nodeid always returns nodeid of "template" rather than node id of "content node" hence always properties are empty. can you please suggest how to get node id of content which is published.
<umbraco:Macro runat="server" language="cshtml">
@{ var nodeid = umbraco.NodeFactory.Node.GetCurrent().Id; var ApplePath = Library.NodeById(41707).GetProperty("appLink").Value; var GooglePath =Library.NodeById(41707).GetProperty("googleLink").Value; }
What exact version of Umbraco are you using? If you're using Umbraco 6 or 7 you can should be able to get the node id by writing @Umbraco.Field("Id") for instance.
The code above looks pretty outdated - But of course it depends on the version of Umbraco you're using.
That's because in your code you are using <umbraco:Macro runat="server" language="cshtml">. I think it might be better to create an actual macro and place that on your masterpage.
In Umbraco 6 pages are webforms by default, but it might be easier to switch to MVC mode so all your templates are Razor files.
Access Umbraco published content from .master page.
Hi,
This is may be a basic question, can anyone help please, I am unable to get properties of template from .master page. I have a content node which uses template (.master page) , I would need to access two properties in master page (document type contains 2 properties to which content node is pointing) please find the sample attached below. I dont want to hardcode the node id, hence would like to get it dynamically. In below example nodeid always returns nodeid of "template" rather than node id of "content node" hence always properties are empty. can you please suggest how to get node id of content which is published.
<umbraco:Macro runat="server" language="cshtml">
@{
var nodeid = umbraco.NodeFactory.Node.GetCurrent().Id;
var ApplePath = Library.NodeById(41707).GetProperty("appLink").Value;
var GooglePath =Library.NodeById(41707).GetProperty("googleLink").Value;
}
</umbraco:Macro>
Thanks
Satish
Hi Satish
What exact version of Umbraco are you using? If you're using Umbraco 6 or 7 you can should be able to get the node id by writing @Umbraco.Field("Id") for instance.
The code above looks pretty outdated - But of course it depends on the version of Umbraco you're using.
/Jan
Thanks Jan,
I am using 6.2, I followed your suggestion, and now getting following error although assembly is referenced, any idea?
The type or namespace name 'Field' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)
Regards
Satish
Hello,
That's because in your code you are using <umbraco:Macro runat="server" language="cshtml">. I think it might be better to create an actual macro and place that on your masterpage.
In Umbraco 6 pages are webforms by default, but it might be easier to switch to MVC mode so all your templates are Razor files.
http://umbraco.com/follow-us/blog-archive/2012/10/30/getting-started-with-mvc-in-umbraco-410.aspx
http://umbraco.com/follow-us/blog-archive/2013/7/14/moving-from-webforms-to-mvc
Jeroen
is working on a reply...