Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • satish 8 posts 29 karma points
    Feb 24, 2015 @ 16:43
    satish
    0

    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

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 24, 2015 @ 16:48
    Jan Skovgaard
    0

    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

  • satish 8 posts 29 karma points
    Feb 25, 2015 @ 10:21
    satish
    0

    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

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Feb 25, 2015 @ 12:04
    Jeroen Breuer
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft