2

In MVC there's the concept of Partial Views which helps refactor common code that can be reused by other Views.

Is there a similar concept in SXA Scriban?

Ideal example:

List of Links Template:

{{ for i_links in i_datasource.FooterLinks.children }}
    {{ render "Custom Partial" i_datasource }}
{{ end }}

Custom Partial:

<h6>{{ i_datasource.Title }}</h6>
{{ i_datasource.text }}
{{ i_datasource.link }}

It would be good to declare this Custom Partial in a global scope for the current site so it's not tied to any rendering variant.

2

Maarten Willebrands has just released a module that can do this: https://www.maartenwillebrands.nl/2021/02/23/sitecore-sxa-scriban-includes/

Within plain Scriban it is possible to use includes, which allows you to render another Scriban template where you call the include. This makes sure you can re-use parts of your templates, and makes sure you can define your templates in a modular way.

SXA does not offer the include function out of the box, but luckily for us, there are enough extensions points. I’ve developed a SXA module called Sitecore Scriban Extensions, which makes it possible to use includes within SXA. All the code and Sitecore items that are needed are located on this GitHub page, and you can download a Sitecore Installation Package as well.

I didn't test it yet (on my to-do list), but it looks very interesting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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