Copied to clipboard

Flag this post as spam?

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


  • mrclan 8 posts 79 karma points
    Nov 27, 2016 @ 16:11
    mrclan
    0

    How to reuse content on different pages ?

    Hello everyone, a very new Umbraco user here. I've a situation like this. I want a header and footer section that can be edited by a content editor. And then I want to use them inside a master template, so that they are automatically added to all the child pages.

    But I'm unable to think of a way to structure my document types to do this ? Any hint on how to do this, would be really helpful. Thanks.

  • Marcio Goularte 388 posts 1360 karma points
    Nov 27, 2016 @ 23:16
    Marcio Goularte
    0

    You can add the header and footer properties in the root site content and get them in the master template these ways:

        @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
        @{
            Layout = null;
    
            var home = CurrentPage.Site();
    
            var home2 = Umbraco.ContentAtRoot().First();
    
            var home3 = Umbraco.TypedContentAtRoot().First();
    
        }
    
    //dynamic    
    @home.header
    @home.footer
    
    @home2.header
    @home2.footer
    
     //Typed       
    @home3.GetPropertyValue("header")
    @home3.GetPropertyValue("footer")
    

    will appear on all child pages of this master template

  • mrclan 8 posts 79 karma points
    Nov 28, 2016 @ 00:12
    mrclan
    0

    Thanks for your reply Mario. But when I try to use the child template I get this error:

    "Cannot bind source content type Umbraco.Web.PublishedContentModels.Room to model content type Umbraco.Web.PublishedContentModels.Site"

    And, when trying to use master layout doctype, I get this one:

    The file "~/Views/Site.cshtml" cannot be requested directly because it calls the "RenderBody" method.

    Any suggestion regarding this ?

  • Marcio Goularte 388 posts 1360 karma points
    Nov 28, 2016 @ 00:32
    Marcio Goularte
    0

    You are trying to use ModelBuilder. The code I posted is using dynamic and typed IPublishedContent. Particularly I still do not use ModelBuider, for now I do the traditional way in Umbraco. Show your code to understand better.

    See this link that explains in a simple way how to do. http://www.alexlindgren.com/archive/site-building-with-umbraco-7/

  • mrclan 8 posts 79 karma points
    Nov 28, 2016 @ 00:36
    mrclan
    0

    Here's my code for site layout:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Site>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = null;
        var home = CurrentPage.Site();
    }
    
    Content from the site page
        <h1>@home.gHeaderText</h1>
    
        @RenderBody()
    

    Here gHeader is a property for GlobalHeader text which I want to display on all the pages. I add a content node of type Site at root and get that 2nd error mentioned above.

  • Marcio Goularte 388 posts 1360 karma points
    Nov 28, 2016 @ 00:46
    Marcio Goularte
    0

    I do not know how ModelBuider works, but from what I understand you should not put PublishedModels.Site as Model in Master Template. You must use PublishedModel in the context content template. For example, in the template of the node Site you can use:

    Umbraco.Web.Mvc.UmbracoTemplatePage <ContentModels.Site>
    

    but not in the master template. Try only

    Umbraco.Web.Mvc.UmbracoTemplatePage
    
  • mrclan 8 posts 79 karma points
    Nov 28, 2016 @ 00:52
    mrclan
    1

    Thanks Mario for your help. I'm very new to all these concepts like ModelBuilder and PublishedModel. I'll do some research and skim through documentations first. Hopefully I'll find some good resources to go through.

Please Sign in or register to post replies

Write your reply to:

Draft