2

Let's imagine I have an item with in three language versions: en, jp and es.

My goal is to render a block which will display all 3 language versions of the item's 'Description' field.

So, I would go for the {{for ...}} loop, but how do I iterate through the language versions of an item in the scriban?

3

I don't think you can do this ootb.

One solution would be to create an extra Scriban context function. That is not hard to do - you can find how on https://ggullentops.blogspot.com/2019/11/custom-sxa-scriban-extensions.html

This function would return all the language versions of a given item. You can loop through the results. It would look something like:

public class ScribanLanguageVersions : IGenerateScribanContextProcessor
{
    private readonly IContext context;

    public ScribanLanguageVersions(IContext context)
    {
        this.context = context;
    }

    public void Process(GenerateScribanContextPipelineArgs args)
    {
        var lv = new GetLanguageVersions(Versions);
        args.GlobalScriptObject.Import("sc_languageversions", (Delegate)lv);
    }

    public Item[] Versions(Item item)
    {
        return an items list for all languages;
    }

    private delegate Item[] GetLanguageVersions(Item item);
}
2
  • Thanks for the suggestion. I think, in my case it would be better just to go on with standard MVC approach instead of customizing SXA Jun 30 at 11:23
  • Adding an extra function for Scriban is not that much work and will allow you to continue using the sxa features.. but of course you can and should do what feels best for you.
    – Gatogordo
    Jun 30 at 12:12

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.