1

I am trying to render a dynamic placeholder with the Scriban as follows:

{{ sc_placeholder 'section' }}

and I would expect it to add a number to the key i.e. section-3, etc, but this is what I see as a result: enter image description here

which is not what I expected.

P.s. I have the IsRenderingsWithDynamicPlaceholders property set to true on my rendering item.

Is there anything I am missing?

2
  • 1
    I could be wrong, it is only an assumption, but I think that your Scriban template doesn't know anything about parental controls in the rendering runtime. (Otherwise, performance will be poor). That is why SXA thinks that it is the first placeholder section in this context and doesn't add the dynamic suffix.
    – Anton
    Dec 28, 2021 at 17:53
  • @Anton thank you. for now I will just create a .cshtml rendering, but let's keep the question open in case anyone has any ideas Dec 29, 2021 at 9:22

3 Answers 3

3

Using asterix at the end of your placeholder key in Scriban will solve your issue. (It works well in SXA 10.1)

{{ sc_placeholder "myplaceholderkey*" }}
2

I was finding that using the wildcard naming convention (with the * ) did not work with Sitecore 9.3. I suspect they added support for using the wildcard convention in Sitecore 10.

If you are on Sitecore 9.3, an alternative is to roll your own dynamic placeholder logic. Taking a cue from how SXA does it, you can leverage the value of the DynamicPlaceholderId rendering parameter. For example:

{{ dynamic_placeholder_id = sc_parameter "DynamicPlaceholderId" }}
{{ sc_placeholder "NameOfThePlaceholder-" + dynamic_placeholder_id }}

You could also take this a step further and write your own custom Scriban extension that leverages the same DynamicPlaceholderId value and then you could call it like this:

{{ sc_dynamic_placeholder "NameOfThePlaceholder" }}
1
  • I have found that there is a Sitecore patch/fix/package for this to allow for the wildcard syntax to work in 9.3. The package name is: SC Hotfix 394455-1 SXA 9.3.0.2589
    – Mike M
    May 26, 2022 at 19:52
0

Use the asterisk sign at the end of the placeholder name: Ex.

{{ sc_placeholder "NameofthePlaceholder*" }}

and it will add no to the key like this NameofthePlaceholder-1-1

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.