1

Is it possible to nest master pages or razor views?

I was trying to get this working, and it seems like only the directly referenced template is loaded.

So if I have MasterTemplate which contains script references and the site footer, and child templates CustomerTemplate & SiteTemplate which contain the rest of the site structure, the scripts and footer aren't getting pulled in.

Andrew Walters
  • 4,763
  • 6
  • 35
  • 49

1 Answers1

0

Composite C1 is relying 100% on the underlying ASP.Net technologies, so nesting masterpages or creating layouts for razor pages is done in a purely vanilla asp.net way.

Read about it on these lins

You might need to do some of these things through a code editor like Visual Studio though.

Master Pages

Create the template in C1 as usual, but afterwards you add the MasterPageFile attribute in the <%@ Master %> declaration. Let it point to another .master file you have created through Visual Studio in which you add one or more <asp:contentplaceholder /> elements. Back in your C1 template, you wrap all the content in a <asp:Content /> element, while deleting head, footer and whatever is defined in the parent master.

Its important that you keep the Placeholder definitions in your C1 template, those you can't move to the parent master. Also make sure to put your <c1:Render /> elements inside the <asp:Content /> element.

Pauli Østerø
  • 6,878
  • 2
  • 31
  • 48
  • I was getting a build error using the master pages wrapped in a tag like in the demo http://docs.composite.net/Layout/Master-Page-Templates/Creating-Master-Pages/Visual-Studio No build errors on the razor template side, but it didn't seem to want to load in the parent template's content. Have you done the nested templates before? Maybe you could post up some sample code for me? – Andrew Walters Jun 24 '15 at 23:49
  • Updated answer with a quick walkthrough for masterpages. – Pauli Østerø Jun 25 '15 at 12:40
  • Cool, I got a test going with the .master pages by dropping the tag which was wrapping the child master page. The site I'm working in at the moment has some templates built out using the razor syntax. Are there any tricks to nest those? – Andrew Walters Jun 26 '15 at 13:23
  • The basic idea is the same for Razor files. Set the Layout-property of your template to a .cshtml file you've created in Visual Studio and let that file contain a RenderBody() call, which will render the content of referencing template at that location. – Pauli Østerø Jun 26 '15 at 15:36