8

This is something that's been bugging me and I was curious to others' solutions. Let's say you have a template that you've done standard values on for the presentation...you pick a layout, put renderings on, put placeholder settings on. Let's say one of these renderings is a sub-layout (in the traditional sense of the word, not an web forms rendering) with placeholders on it.

Is there a way to specify the placeholder settings for the sub-layout such that they always stay with the sub-layout? I hate the idea of having to specify all of these placeholder settings on a page template that may or may not use the sub-layout, and I'd hate to always have to specify a template for the sub-layout if all it is is a layout detail (like multiple columns to subdivide a page) and doesn't need a template for data reasons.

Thoughts? Thanks.

6
  • Are you referring to pinning a component on a page? Like "news article will always have a embedded content component, which can't be removed"?
    – Ben Lipson
    Commented Oct 14, 2016 at 20:27
  • No, more like I have a sub-layout called Three Columns, with three placeholders (left, right, middle). I want placeholder settings for those three columns, but I want them to be associated with/follow the sub-layout. Right now I'm anticipating them by putting the placeholder settings on the page template level, which is overkill for the page template. But I'm trying to avoid needed a template just to support the sub-layout if that makes sense. Commented Oct 14, 2016 at 20:30
  • Actually, thinking about it. What about a baked-in template that has the placeholder settings, that I connect up to the sub-layout rendering in the rendering definition itself? Since there's no other data template, in the case I'm thinking of, that will ever be connected, that should work, no? (if folks agree I'll post it as the answer.) Commented Oct 14, 2016 at 20:33
  • Can you create placeholder settings items for left, right, and middle under /sitecore/layout/Placeholder Settings and define your allowed controls there? This does not require anything to be done on the template or component levels. Commented Oct 14, 2016 at 23:40
  • I could, Derek, but then I'm creating three placeholder settings when one might do. If we consider this as a three-column layout (each column is col-md-4), then each placeholder might take a "Single Column" placeholder setting. I think I see what you're saying, but I'd want to reuse the placeholder setting. Commented Oct 15, 2016 at 1:01

2 Answers 2

6

I think the most common extension is to use the rules engine. You create a processor for the GetPlaceholderRenderings pipeline that uses the rules engine to add/remove renderings. Here are some links to various implementations of the idea. I'm sure there are more out there too.

1

I'm going to answer my own question, but I'd like to see opinions on whether folks think this might be the answer.

So in this scenario, the rendering that is my sub-layout has no actual data going to it; it's purely a placeholder deal. Think a main layout that has a Bootstrap col-md-12, and I want a sub-layout that has three col-md-4's, with a placeholder in each. So I create the rendering in Sitecore, connect to a CSHTML file with the markup, and in theory I'm done except for "where do I put the placeholder settings?"

So on the layout page connected to the template, we have this:

<div class="col-md-12">
    @Html.Sitecore().Placeholder("main")
</div>

The placeholder settings for "main" can be assigned as the default key on the placeholder setting itself, as discussed below. Then we have a rendering that consists of the following, with no template required because it's just placeholders:

<div class="col-md-4">
    @Html.Sitecore().Placeholder("main-left")
</div>
<div class="col-md-4">
    @Html.Sitecore().Placeholder("main-center")
</div>
<div class="col-md-4">
    @Html.Sitecore().Placeholder("main-right")
</div>

Each of these placeholders would use the same placeholder setting, let's call it "Single Column". So the question is, where do I assign "Single Column" to affect these three placeholders? With the caveat that this rendering may not be used, and I'd prefer not to junk up my page template with placeholder settings that may never be used.

I can't put them on the rendering, that doesn't work correctly. So after spelling the case out above, the thought that came to me is to create a template with no fields, and all it has on it are placeholder settings. I then attach that template to my rendering in the "Data Source" field, so they're always connected.

In theory this would work. The one thought that occurs to me as I write this, in the standard values of the template to specify the presentation details, can you specify just the placeholder settings, or does it force you to pick a layout and perhaps a rendering as well? If so, could you create a completely blank layout (I mean a CSHTML file that's totally empty, no markup at all) and then pick some dummy rendering that's connected to an unused placeholder key (so it could never render on the page) just to trick the system?

It sounds like a long way around to achieve the effect, but the ultimate goal is, for these renderings that are nothing more than sub-layouts that contain placeholders, to keep the placeholder settings with the sub-layout, and not "junk up" the page template with placeholder settings/keys it might never use.

9
  • I'm confused about what you need to do Ken. You do not assign placeholder settings to specific rendering.
    – josedbaez
    Commented Oct 17, 2016 at 7:58
  • And maybe this is where I'm over engineering, but I'm trying to get things handled better. On my page template, I have a single placeholder that spans the whole page, easy enough to assign a placeholder setting to the template and hook it to the key. Now I create a rendering that's intended as a sub layout...it has three columns with three placeholders, each with their own key. I have a single placeholder setting called "Single Column" that I can assign to each of these three columns. Where best to assign the placeholder settings for my sub layout? Page template? Commented Oct 17, 2016 at 18:33
  • I'd create the placeholder setting item and set components allowed there, and leave the key empty. Then on the standard values of the pages where this will be used, add a placeholder rendering pointing to the newly created and set the placeholder name (do this for each of the columns) see: varunvns.wordpress.com/2014/07/07/… Might be confusing at the beginning but once you do it couple of times you'll master it.
    – josedbaez
    Commented Oct 17, 2016 at 23:21
  • That did help me understand and trim down the number of placeholder settings I had to apply to templates directly. I'm still having some confusion/issue with the specific case I'm thinking of, so I'll see if I can follow up later when I have time with some screenshots of what I'm doing to facilitate discussion. Thanks for the pointers so far. :) Commented Oct 18, 2016 at 13:39
  • josedbaez - I added some code samples above to try and better describe where I'm going with it. Does that still jive with where you're going? Thanks. Commented Oct 19, 2016 at 1:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.