Add a dynamic placeholder to a rendering variant

Abstract

Use dynamic placeholders to add the same placeholder name several times.

SXA lets you create rendering variants that render a placeholder that enables users to add additional renderings. You can add restrictions to the placeholder settings. For example, because you only want to content author to add an image rendering. When you use dynamic placeholders, you can add the same placeholder name several times across multiple renderings or within a single rendering. Dynamic placeholders guarantee that unique keys are used across different renderings and within one rendering.

To add a dynamic placeholder to a rendering variant:

  1. Add a rendering variant. For example, add a variant for the Page Content rendering.

  2. Right-click the variant, click Insert and click Placeholder.

  3. In the VariantDetails section, add the Placeholder Key. Do not use a dash in your Placeholder Key name, this may impact the key resolving logic. If you leave the field empty, the key will be generated automatically.

    Warning

    You must not change Placeholder Keys when they are in use, nor change the order of existing placeholders, nor add a placeholder before any of the existing ones. Once a placeholder is generated on the page (with a Placeholder Key assigned) and it contains renderings, changing the key will make the renderings disappear. The renderings will be hidden because they cannot find their placeholder path.

  4. If you want the user to be able to switch context for the renderings inside this placeholder, go to the VariantDetails section and select the Switch component context to currently rendered item checkbox.

  5. To reference the placeholder key that you just created in the Placeholder Settings, go to Presentation/Placeholder Settings and add a placeholder.

  6. In the Data section enter the Placeholder Key that you just created and add an * to make it dynamic and guarantee a uniqueness to the placeholder key across different renderings.

  7. If you want to restrict the use of renderings in this placeholder, in the Data section, in the Allowed Controls field, click Edit and select the renderings that are allowed. For example, go to Layout/Renderings/Feature/Experience Accelerator/Media and select the Image rendering.

    Placeholder
  8. If you now add the Page Content rendering to the page and select the variant that you just created, you will see that the only available rendering that you are allowed to add is the Image:

    Select a renndering