Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Topic author was deleted
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?
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?
This I want my Master View to rendersection("footer") and RenderBody() (basic pages)
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
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
Oh yeah I forgot.
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.
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:
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:
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 :)
Thank you very much! Very knowledgeable, good luck, czesc! It worked.
Glad that it helped, pozdrawiam! :)
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted