Shared page element across multiple templates

Jon Tetzlaff asked on October 5, 2015 20:53

A site I am currently working on has a sidebar on it, but only on certain pages. How would you go about making a sidebar that is shared across those pages so when someone makes a change to it on one page, it is made on all instances of the sidebar? Is it even possible?

I know I can easily replicate the sidebar to each template that needs it, but I'm not sure how to accomplish the above.

Correct Answer

Jon Tetzlaff answered on October 7, 2015 17:30

What I'm going to end up doing is adding the sidebar to my root master page, then adding a ShowSidebar property to the Page Menu Item page type. That way editors can change the sidebar on the master page and any page below that is has checked the ShowSidebar property will get a sidebar.

The sidebar code is wrapped with this logic in the master template
<% if(CurrentDocument.GetValue("ShowSidebar", false)) { %> ...sidebarcode <% } %>

Thanks for your replies. I think each of the solutions could work in different situations.

0 votesVote for this answer Unmark Correct answer

Recent Answers

Bryan Soltis answered on October 5, 2015 21:33 (last edited on October 5, 2015 22:09)


i'm pretty sure you can achieve what you want using inheritance. You can make a master page with the sidebar in it, then just be sure to inherit that for all of your sub pages. If you site is a simple structure, you can do this on the Root level. That would cause he sidebar to be visible on all pages. If you need to have a 1-2 pages without it, you could just make them stand alone pages (with all design elements as the master page). If you have more areas of the site that need to not have the sidebar, you may have to make a few more master pages and have those section inherit those.

1 votesVote for this answer Mark as a Correct answer

Ilesh Mistry answered on October 5, 2015 23:36

Hi Jon

I agree with Bryan, that you could use a selection of Master Page and Sub Master Page combinations to achieve a side bar change for all route. However from your description above, I think you might be looking for something else? If you are please reply back with some more information e.g. where is this side bar? On the master page? Or just a template? Is it a web part or widget or static text or something else? etc...



0 votesVote for this answer Mark as a Correct answer

Jon Tetzlaff answered on October 6, 2015 18:16


Thanks for the answers. The sidebar will be located on some, but not all, interior pages (About us, product pages, clearance page). Ideally I would have one instance of the sidebar that would go on all of these pages and could be edited from one place. The sidebar would have to be update-able with webparts. The site I am building already exists, so I am trying to keep the url structure similar in the Kentico version.

If I did use another master template would I have to basically copy my root master pages code? I don't want to have to make changes in two master files.

0 votesVote for this answer Mark as a Correct answer

Laura Frese answered on October 6, 2015 18:50

You can just create a separate template, you don't need 2 masters. One template for inner pages without the side bar, another with the side bar. Alternatively, if there are web parts that you want to show on some pages but not others you can also use macros in the visibility section of the web part. Just click on the little black triangle next to the Visibility checkbox and it will open the macro editor. You can enter something like: {% if(CurrentDocument.DocumentName == "MyPage") {return true;} else {return false;} #%}

While macros may not be the way to go here since every time the pages load it has to check the page name & may slightly slow down load time, it may keep things neater in the Templates folder since you wont need different templates every time you want to show a different web part.

You can read more about how amazing macros are on my blog post Here

1 votesVote for this answer Mark as a Correct answer

Jon Tetzlaff answered on October 6, 2015 21:57


Thanks for the response. That sounds like a lot of overhead and complexity in my particular situation. If the site I was working on was simpler that may work, but unfortunately I don't think it will in my case. I was afraid there wouldn't be a good solution in Kentico :(

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on October 6, 2015 22:08

The easiest thing to do here is what Laura suggested. Having sub templates that have the different zones is going to be much easier, plus that is really what the templates are supposed to be for. A master page is mainly for the header and footer of a site, so if that look and feel is the same, then no reason to create another master page. Create one page template with a zone for the menu, and another without it. Then assign either one of those templates to your pages and you are done.

If you need another variation, then you just clone the template, and add to it or remove items, then you assign it to the corresponding pages. Just make sure that when you make a change to a template, you are aware of the pages that it will affect.

1 votesVote for this answer Mark as a Correct answer

Ilesh Mistry answered on October 7, 2015 14:53

Hello Jon

I am not sure if you are still looking into this?

If you are and the above great suggestions are not ideal for you, another option is to have a bank of common data somewhere in the Kentico tree. An example of this would be something like a common elements bank/folder. Then within here you can have that side bar configured in one place and then use it on the different templates.

Hopefully what I am suggesting with the common elements folder makes sense? The idea is to then use this place to make the single change and then see it appear on the pages that use it.

I would go one more step further and think about Kentico EMS and convert the web part that would be appearing on different pages into a Page Widget (I guess you don't need Kentico EMS to still do this). In using this approach you won't need lots of different templates and can decide to keep the side bar on the pages you want that have a widget zone.

Hope this helps.


0 votesVote for this answer Mark as a Correct answer

Jon Tetzlaff answered on October 7, 2015 15:55 (last edited on October 7, 2015 16:14)


I was starting to lean towards doing something like a shared content section. I'm just not sure how to accomplish what you are saying it in Kentico, as I'm kind of a newbie still. I will look into widgets more to see if that can help.

0 votesVote for this answer Mark as a Correct answer

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