Copied to clipboard

Flag this post as spam?

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

  • Sjoerd Stottelaar 25 posts 175 karma points
    Oct 03, 2019 @ 10:10
    Sjoerd Stottelaar

    Get value from document type in master page

    I want to add a canonical URL to my master page which is coming from the document type. So on my document type I have a node picker where I can select a page from the content tree. I want to render this URL in the head section of my master template. Is this possible?

    I've tried many things, the most obvious ones didn't work:

    var canonicalUrl = Model.Value("metaCanonical").Url


    IPublishedContent canonicalUrl = Model.Value("metaCanonical")

    I'm aware that the master page can't inherit any specific model, this is what my master template inherits:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage

    Any suggestions as to how I can access the page URL from the node picker? Thanks in advance!

  • Mila Pandurska 75 posts 349 karma points
    Oct 04, 2019 @ 08:24
    Mila Pandurska

    Hi Sjoerd, You can achieve this using standard MVC sections. In the master page place this in the head section:

    @RenderSection("Head", false)

    Then in your tempates which inherits this master page place this:

    @section Head

    You can name the section as you wish (not necessary to be "Head").


  • Sjoerd Stottelaar 25 posts 175 karma points
    Oct 04, 2019 @ 09:46
    Sjoerd Stottelaar

    Thank you for your suggestion, I think we'll go with this solution. We'd need to add the section to every page, but I think it's the only way to get it working. Thanks alot!

Please Sign in or register to post replies

Write your reply to: