Copied to clipboard

Flag this post as spam?

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


  • Topic author was deleted

    Oct 21, 2016 @ 00:42

    Question regarding, layout view, sub template and renderbody()

    Hello. I am having trouble with using RenderBody() and Layout.

    First of all, how do I know that I created a Layout View? Is Layout = null; it?

    enter image description here

    I want to use this as my master layout, then have a sub template under it that uses RenderBody()

    Is this the proper way of doing things?

    enter image description here

    This I want my Master View to rendersection("footer") and RenderBody() (basic pages)

    enter image description here

    So this error means my Layout view isn't actually a Master Layout view, if so how do I make it the actual master template, and will this then allow me to use RenderBody() in it

    Thank you

  • Marcin Zajkowski 97 posts 558 karma points MVP 2x c-trib
    Oct 21, 2016 @ 01:00
    Marcin Zajkowski
    1

    Hi Maciej,

    what type of error are you receiving? This is the most important quesiton now :)

    Basically, you need to have Layout = null; only at your masters - that's correct - and then, Layout = "Master.cshtml"; (or any other mastertemplate filename) on all templates for which pointed Master should be a masterpage.

    Then, you need to place @RenderBody() on your Master.cshtml and that's it.

    I can see that you have other file called Layout.cshtml. I presume that it's another master template? You need to also check if there is a model / document type representation for template which you're going to use. Usually masterpages are not related with particular document types, so the inheritance and models mapping is not required there. Share more details please.

  • Comment author was deleted

    Oct 21, 2016 @ 01:23

    Oh yeah I forgot. enter image description here

    So I have "Layout" as the Master template that calls for "Master" views using RenderSection(). Then on my Master view I call RenderBody() and call various views - contact, about, etc.

    Layout.cshtml is the topmost template and the only one with layout=null;, the "King" template, then my Master.cshtml view have RenderBody(), RenderSection("footer"), nav bar.

    Some details: enter image description here enter image description here enter image description here

    enter image description here enter image description here

  • Marcin Zajkowski 97 posts 558 karma points MVP 2x c-trib
    Oct 21, 2016 @ 08:01
    Marcin Zajkowski
    1

    Hey,

    error is telling you everything :) You shouldn't use master page as a document type and content element, as it is just responsible for having the template values which are shared between templates and pages.

    Additionally, you don't need both: Layout.cshtml and Master.cshtml in your scenario if they are not used as a content nodes in the content tree.

    In document types you should declare items which will be used as a content nodes. Then in the templates you can creaet Master template with shared content (without inheriting model for this template) with just a simple call for @RenderBody() of a child templates and/or @RenderSection() if it's needed. I also suggest to add required: false for section as it won't force you to include section on every child page.

    I suggest you to check how it's done on Fanoe startertkit for example, as there is a simple structure with Master template:

    enter image description here

    and as you can see, Master don't have document type item, as it is not used as a node in the content structure.

    Master just inheriting current UmbracoTemplatePage:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = null;
        var home = @CurrentPage.Site();
    }
    

    and later calls @RenderBody() wherever it's required. Then e.g. Home template, just points to the Layout = "Master.cshtml" and includes content which will be rendered on master in the render body section.

    Hope that it will give you some explanation how it should be done. Let us know if you'll fix it :)

  • Comment author was deleted

    Oct 21, 2016 @ 16:19

    Thank you very much! Very knowledgeable, good luck, czesc! It worked.

  • Marcin Zajkowski 97 posts 558 karma points MVP 2x c-trib
    Oct 21, 2016 @ 16:42
    Marcin Zajkowski
    0

    Glad that it helped, pozdrawiam! :)

Please Sign in or register to post replies

Write your reply to:

Draft