How to share a template amongst multiple pages and define an 'instance unique' web part zone?

Lance Keay asked on November 8, 2016 12:58

I've seen this question: http://devnet.kentico.com/questions/one-template,-multiple-pages,-varying-web-parts but hopefully there is a better answer.

I'd like to be able to define a page template with multiple web part zones, and select zones which can have unique content per page.

eg: - The master page contains the header and footer, along with a single web part zone containing as single pageplaceholder. - The 'my account' page template contains 3 web part zones - leftZone, mainZone, and rightZone.
- This template will be shared amongst 10 'account' pages. - The content of the leftZone won't change between pages, it's a navigation area for the account section. - The mainZone will vary between each page - sometimes a user control, sometimes editable text, sometimes repeaters, etc. - The rightZone content will also vary between each page.

I know that I can create a single page template and then clone it as an ad-hoc per page. This is NOT what I want. I'd like to share the single template - if there are html changes to do, I'd like to do them in one template, rather than on a dozen ad-hoc templates.

I note that it's similar to the difference between the staticText and editableText web parts. The staticText will have the same content for all instances of a template, while the editableText will have unique content per page. I'm asking how to get the effect of an 'editable' web part zone.

Recent Answers


Trevor Fayas answered on November 8, 2016 15:40 (last edited on December 10, 2019 02:30)

A couple things to note that may aid you, then i'll get directly to your question.

Firstly, Page template's have a Page Layout (the html and where webpart zones are), you can create shared page layouts and assign templates to them, so this may resolve in an easier fashion the "I want multiple templates but when the html changes i want to do it in one place."

Likewise, if a webpart zone is named the same (say "leftZone, mainZone, rightZone" if you switch a page's template to another template that has the same named webpart zones ("leftZone, mainZone, rightZone") all your webparts will migrate into the new location.

Back to answering the actual question, you can use macros to hide/show webparts (the visibility option on them). There is a macro for CurrentDocument.DocumentPageTemplateID, you will probably want to create a custom macro method to pass it the codename of the template and get the ID to make your life easier (and to account for different page template IDs in staging/live environments).

So something like

Visible: {% CurrentDocument.DocumentPageTemplateID == Util.GetTemplateID("MyTemplate") |(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on November 8, 2016 16:18 (last edited on November 8, 2016 16:25)

Your idea about place holders is correct, ad-hocing is very bad.

You can also for example: create a shared footer for all master templates. Create a master page with footer only. You can add place holder to all your master templates where you want to this footer to appear and set "page to display" property to the master footer page. Now all your master pages have the shared footer. And you can manipulate with properties like visibility using macros.

You might as well take a look at the page nesting for templates link text

1 votesVote for this answer Mark as a Correct answer

Lance Keay answered on November 9, 2016 15:07

Thanks for the help guys. @trevor - I just spent some time playing with the Shared Page Layouts. They are pretty good! It allows us to update the HTML in one place for a bunch of templates that use the Shared Layout.

Is there a way to combine the functionality of the normal page Template and the Shared Layout?

eg: every page using the RightSide template will have a zoneHeading area with breadcrumbs, and a left navigation (zoneLeft) that's shared between all the pages. These controls don't change ALL pages using this Template/Layout should have these. However, the zoneContent in the middle and the zoneRight should have different Web Parts per page instance.

Is there maybe a property of the WebPartZone that allows shared content for each page instance or forces unique content per page instance?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.