Hot answers tagged

6

Yes, it is possible. Keep in mind that Scriban by default is lower casing properties and using underscore to separate the words. So property called VariantFields will be accessible in Scriban by variant_fields. Take a look here: Please refer to the Scriban documentation for more details: https://github.com/lunet-io/scriban By default, Properties and ...


6

Yep! You can do it by adding Rule item under your Sriban template item and using sc_evaluate function inside of the template. Example: I have a page which has two fields: Title Brand And I want to render Brand field only when it is Monday. In order to do that I'm using Page Content rendering (can be any other) with following rendering variant: And the ...


3

Scriban has a split function on strings: https://github.com/scriban/scriban/blob/master/doc/builtins.md#stringsplit string.split <text> <match> The split function takes on a substring as a parameter. The substring is used as a delimiter to divide a string into an array. You can output different parts of an array using array functions. Also ...


3

Try using an extension. See https://gist.github.com/auzick/c2e127ed4c6aef0f019eedc0ab738d2b. using Scriban.Runtime; using Sitecore.Data.Fields; using Sitecore.Data.Items; using Sitecore.XA.Foundation.Abstractions; using Sitecore.XA.Foundation.Scriban.Pipelines.GenerateScribanContext; using System; namespace Example.ScribanExtensions.Pipelines { public ...


3

The reason why you cannot access those properties is because they are not know in the Scriban context provided by the SXA extensions. If you have i_item.CardLink in your Scriban template, that will match a Field object. This object has some properties (eg Target), but not the properties from a LinkField. And those are the ones you are requesting. There is a ...


2

First of all, you don't need to have a delegate there. It is useful when your function can accept optional parameters. You won't do it in Func and that is why we are using delegate. Otherwise, you can do something like that and skip delegate: args.GlobalScriptObject.Import("sc_link", new Func<Item, string>((item) => { // something return ...


2

You have 2 options. Duplicate the scriban template into the Hero variant and just add the class to the variant. Just have one variant and use an optional Style class tick to add the CSS class that changes the behavior. To decide which to use, think about your end-user and what would be easier for them when authoring the page. To add an opinion, I would ...


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-...


2

Maybe you can use the string split (by '|') function that will get you the array: [www.test.com, www.test1.com]. Then you can read first element of the array using array first function. Example: {{ for word in "Hi, how are you today?" | string.split ' ' ~}} {{ word }} {{ end ~}} output Hi, how are you today?


1

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 ...


1

The version of Scriban that ships with SXA 9.3, 10.0 and 10.1 is 2.0.1 so you only have the functions available on that version of the doc site - https://github.com/scriban/scriban/blob/v2.0.1/doc/builtins.md


1

First - don't reuse the i_item variable, that should stay as the object passed in. Use a new variable name for your loop. Next, you can just nest the sc_follow or sc_followmany to get further down the list. {{for i_pageItem in $consolidatedItems}} {{i_pageItem.path}}<br> {{ for i_child in (sc_followmany i_pageItem "Childrens") }} ...


1

In Scriban we have an embedded function sc_link here you can find more details about it: sc_link An example how to use it : <a href="{{ sc_link i_datasourceItem }}">{{ i_datasource.display_name }}</a>


1

You can try something like the following: {{- childrenCount = i_page.children | array.size -}} {{ childrenCount }}


1

I don't think there is an ootb way to do this (yet). A small extension could help you here. Something like this (not tested): public class MediaUrl : IGenerateScribanContextProcessor { private readonly IContext context; public MediaUrl(IContext context) { this.context = context; } public void Process(...


1

Instead of using {{i_item.Title }} you can use the raw value of the field, that will only render the fields contents and will not add the experience editor ability: {{i_item.Title.Raw }} This will work for Single/Multi-line text and RichText fields. For things like Images/Media, then you can construct the tag manually and use things like sc_medialink or the ...


1

This works {{ if (o_model.address)}} {{ if (o_model.address.id)}} {{ end }} {{ end }} Thanks Marek


1

Never mind, there was an error in my template code. I used i_item.Link, which renders the HTML for the link; when I should have used the i_item.url property instead. Once I fixed this, template worked as expected. {{ text = i_item.Name baseLink = i_item.url hasQsParam = (baseLink | string.contains '?') href = null if(hasQsParam) ...


Only top voted, non community-wiki answers of a minimum length are eligible