0

I'm trying to learn the basics of how to use Scriban to customize Sitecore SXA components. I'm having trouble finding any complete walk-throughs or training that provides a full example start to finish. Does anyone have recommendations on a good place to start?

Ideally, I'd like to learn if I can use Scriban to create a mega menu-style navigation component, but even a simpler example like displaying a list of links would be helpful.

I tried to start with this code snippet I found in the Sitecore documentation, but I get an error that i_datasource is null. Where do I set the datasource? Or, is the datasource automatically the component that is being used? My Scriban renderer in this example is based on the Navigation component.

 {{ for i_child in i_datasource.children }}
<a href="{{ i_child.url }}">{{ i_child.Title }}</a><br/>
{{ end }}
2
  • You can follow this blog - konabos.com/blog/adventures-with-scriban-and-sitecore-sxa – Gaurav Agarwal Mar 2 at 14:09
  • Thank you. That is a helpful site. I know this is a very basic question, but I'm new to Sitecore too, which is why I'm looking for a basic start to finish example. I'm still unsure of how the datasource is working in this example. I see he's using {{for i_child in (sc_followmany i_item "TravelTips") }}. Where is TravelTips set up? – natg504 Mar 2 at 14:33
2

You may see the examples here - https://github.com/scriban/scriban/tree/master/doc See the links in documentation section but these are not specific to Sitecore but will give you the gist of language itself.

Use the Visual Studio Code editor for syntax coloring and auto completion here - https://marketplace.visualstudio.com/items?itemName=adamnaj.sitecore-scriban&utm_source=VSCode.pro&utm_campaign=AhmadAwais

Regarding setting a datasource, you may have created a controller rendering if not create and set the controller to - Sitecore.XA.Foundation.RenderingVariants.Controllers.VariantsController,Sitecore.XA.Foundation.RenderingVariants

or since you are building Navigation component use - Sitecore.XA.Feature.Navigation.Controllers.LinkController,Sitecore.XA.Feature.Navigation

and Controller Action to - Index

Set the datasource location and template in rendering. Set the Parameter Template which should inherit from IRenderingId

Once you have the rendering on page you can set the datasource using experience editor or presentation details and also set the rendering variant-

enter image description here

Your controller rendering and rendering variant name should be same.

Hope this helps

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.