Best Practice for Small Shared Content or Components?

Jake Burgy asked on May 9, 2017 20:57

When designing Kentico websites, I frequently encounter situations where I need to have different templates on a page, but have the pages share a common header or other content which can't be done through normal hierarchy / inheritance means.

Does anyone have any best practices for this? I'm sure there's a dozen ways to do it, but say, for example, you had a common header element that needed to be on multiple areas of the site that contained a macro to pull the correct title (and maybe a brief description).

  • Where would you store this common content? A custom page type? A custom table? Somewhere else?
  • How do you render it on a page? All of the "viewer" web parts seem overkill as they all expect a list of content items, not just a single item. All I want is to be able to point Kentico at a page in the tree and either say "Render this field" (the field would contain HTML/K#), or "Render the editable contents of this page" (by editable text control ID perhaps?).
  • Is there a solution that can be achieved with out-of-the-box Kentico (no custom controls or code)? I'm open to writing a reusable web part if it means never having to worry about this again, but I don't want to write a custom control for each bit of content I want to re-use.

I understand that since we're using the portal engine, we're a bit limited, but basically what I'm looking for is an ASP MVC Partial View (but with Kentico Macro support, obviously) - essentially a small bit of content that is parsed and displayed on the page wherever I'd like.

Anyone have any tips for working with content like this?

Correct Answer

Peter Mogilnitski answered on May 9, 2017 21:49

We have a several major master pages on our web site and we have to share header for them (things like google tag manager, boostrap etc.) For that we use a placeholder web part where we specify "page to display", i. e. we've created a page called it "shared header", put there one web part "Head HTML Code", added the content we wanted share in all page headers. On each on the masters we have a placeholder web part that points to "shared header" page.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on May 9, 2017 22:46

I'd suggest reading this post and the answers. There are several good approaches to take which have been discussed in good detail.

0 votesVote for this answer Mark as a Correct answer

Jake Burgy answered on May 9, 2017 23:03

Thank you both! I was not aware that you could use a Page Placeholder to reference and render a specific content page - I thought it was just for inheritance and you could only have one on a page. We have now set up some simple ad-hoc no-inheritance "blank" pages and are referencing them using placeholders. This works wonders! The web parts included in the "partials" even render in the correct context (the page title, for example, renders the correct page title and not the partial page title). Awesome!

0 votesVote for this answer Mark as a Correct answer

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