8

What is difference between Static and Dynamic placeholder? How to choose one over another?

2

2 Answers 2

15

Simplified, this is how you can think of Sitecore placeholders and how Sitecore uses them to build up your page.

Sitecore Presentation Details, regular placeholders

For any page, Sitecore maintains a "map" of "presentation details". Simplified, this is just a map of placeholder and component. So something like this

  • main (placeholder)

    • heading (component)
    • navigation (component)
    • body_2col (component)
  • left (placeholder - from body_2col)

    • article (component)
  • right (placeholder - from body_2col)

    • callouts (component)

This is Sitecore's default approach. The problem with this approach is, that if if you add body_2col to the same page more than once, this model has a problem. Sitecore's "map" will no longer be sufficient, as there is no way to distinguish for Sitecore between left for the first body_2col and the second one.

Dynamic Placeholders

Dynamic Placeholders solves this problem, by making the placeholders unique. Assuming body_2col used a Dynamic Placeholder instead of a normal one - the picture comes out looking like this:

  • main (placeholder)

    • heading (component)
    • navigation (component)
    • body_2col (component)
    • body_2col (component)
  • left_1 (placeholder - from body_2col)

    • article (component)
  • right_1 (dynamic placeholder - from body_2col)

    • callouts (component)
  • left_2 (dynamic placeholder, from body_2col)

    • newslist (component)
  • right_2 (dynamic placeholder - from body_2col)

    • top3news (component)

When to chose one over the other

For normal placeholders, you can predict the placeholder name (key). This means you can predictably add components to them via the Content Editor interface, programatically, or any other way.

For dynamic placeholders, the name (key) is determined at the time they are injected into the page layout - usually in the Experience Editor. If there are many of them on a page, working with Presentation Details via e.g. Content Editor becomes very difficult for a regular user.

1
  • Thanks Mark. Your explanation is more clear and understandable. Jun 8, 2018 at 11:27
5

Mark Cassidy's response explains the why best. However just to summarize, without Dynamic Placeholders, if you are trying to build a truly reusable website, where you reuse components as much as possible, you will run into issues if you do not use Dynamic Placeholders.

So I would recommend that dynamic placeholders should be at the core of any Sitecore implementation. It's important to know that if you are using Sitecore 9.x you have one already provided to you as part of the Core product. This was introduced in Sitecore 9 because of the huge demand for it from the community.

https://doc.sitecore.net/sitecore_experience_platform/developing/developing_with_sitecore/dynamic_placeholders

If you are using a version prior to Sitecore 9, there are a lot of great options available to use from the community. You can also build your own. The concept of how it works is pretty simple. You basically need to create an extension method for the standard @Html.Sitecore().Placeholder() method, that does a little more than the existing implementation. Then you'll adjust additional pipelines so that when the page renders it knows how to render the page correctly using the hidden placeholder key variations.

Uses a Unique Rendering Id:

Behind the scenes when you call @Html.Sitecore().DynamicPlaceholder("Name") (extension method provided by the module) will add Name_{Guid} to the Placeholder name behind the scenes, so that you can specifically target it.

There are some advantages to the Id approach. If you are working within the Experience Editor, there really isn't too much of a difference. If however, you need to make any changes to the Presentation Details in the Content Editor, It's easier to move around id's than incremental numbers. An incremental numbering system can get pretty complicated if you need to move a substantial part of your page around.

Uses a Index Counter:

Basically behind the scenes when you call @Html.Sitecore().DynamicPlaceholder("Name") (extension method provided by the module), it will spit out Name_0, Name_1 or some variation to that key to allow content editors to specifically target a placeholder on the page.

There are many more articles on the web that aren't necessarily packaged software that you can use as well, especially if you want to build your own (though with most of the ones out there, I don't see a reason why you would).

Your Answer

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

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