How to include another Scriban template in a template as partial?

1.5k views Asked by At

I have a Scriban template, but I want to use partials to include them in the template. How do I include them?

2

There are 2 answers

0
Arun Sharma On

You can use sxa out of the box feature sc_execute for the same: {{ sc_execute i_item "Another Renderer Name" }}

Here another renderer will be field/scriban/query etc and that must be children of the current scriban template. Hope this will resolve your issue.

0
Phillippe Santana On

The feature you are looking for is called include. From the spec:

[...] a function that allows to parse and render the specified template name.

Now, I see that your tags include sitecore. Maarten Willebrands developed an extension to enable it: https://www.maartenwillebrands.nl/2021/02/23/sitecore-sxa-scriban-includes/

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.