6
votes
Accepted
How can I use Sitecore Rules in Scriban templates in SXA 9.3
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 ...
6
votes
Accepted
Using Model in Scriban template
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 ...
6
votes
Accessing Link Field Values in a Scriban Template
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....
5
votes
Accepted
Apply a CSS class to every alternative div using Sitecore SXA
This is not an SXA or Scriban problem, this is a CSS problem. You can use the :nth-child() psuedo-selector to apply a style.
For example, if you want all even-numbered divs to have your .reversed css ...
5
votes
Accepted
How do you detect Edit Mode in the Experience Editor with Scriban?
Yes, there is an embedded object called o_pagemode.
You can use this like o_pagemode.is_experience_editor in an if statement.
You can find all the options for the o_pagemode here: https://doc.sitecore....
5
votes
Accepted
Accessing Link Field Values in a Scriban Template
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 ...
5
votes
Accepted
How do you get value of item tag in scriban template
Sample
Here is an example of how I used tags for listing departments associated with media items.
{{ if i_item.SxaTags != "" }}
<span>
Department:
</span>
{{ tags = [] }}
{{ for ...
3
votes
Accepted
Handling multiple language versions of an Item in Scriban
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-...
3
votes
Accepted
Sitecore container with variants to change background color
The Container component is not a Variant component, so you can't create variants for it.
You have 2 options, the best as has already been mentioned, just add a Style option for the Container component ...
3
votes
Accepted
SXA Scriban Dynamic Placeholders
Using asterix at the end of your placeholder key in Scriban will solve your issue. (It works well in SXA 10.1)
{{ sc_placeholder "myplaceholderkey*" }}
3
votes
Accepted
How to increment value and use it in sc_placeholder
I have tried this and not managed to get the ++ increment variable to work, but a simple index = index + 1 does work. Change your template to this:
{{- index = 0 -}}
{{~ if i_item.has_children ~}}
{{~ ...
2
votes
Accepted
Is there a way to get a user object in Scriban?
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 ...
2
votes
Accepted
How do you count the number of children in a Scriban template?
You can try something like the following:
{{- childrenCount = i_page.children | array.size -}}
{{ childrenCount }}
2
votes
Accepted
Scriban template split string
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 ...
2
votes
Scriban template split string
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:
{{ ...
2
votes
Accepted
Is there a way to do Scriban partial templates?
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 ...
2
votes
Accepted
Where can I find Scriban training or examples?
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 ...
2
votes
Accepted
Is there a way to render scriban templates without the use of SXA Rendering Variants?
I have found the use of SPE to be great for this kind of thing. Here is an example on how to render a scriban template.
Example: The following uses Sitecore PowerShell Extensions to render a scriban ...
2
votes
SXA Scriban Dynamic Placeholders
I was finding that using the wildcard naming convention (with the * ) did not work with Sitecore 9.3. I suspect they added support for using the wildcard convention in Sitecore 10.
If you are on ...
2
votes
Accepted
Search Result Listing Get index of an item using Scriban
I am afraid there is no way to do it because variant is used to generate each result separately not the whole list.
This is a place where items from index are prepared
Sitecore.XA.Feature.Search....
2
votes
Accepted
Is there any way to edit partial design using Scriban?
A partial design works just the same as the other items/pages when it comes to adding components and styling those. You can open the partial design in the Experience Editor and add all the components ...
2
votes
How can I do more complex loops in my Scriban templates?
Yes, there are options to create loops like this in scriban:
The offset parameter
This is the scriban equivalent of .Skip() in .net. It allows you to start the iteration of the loop by skipping the ...
1
vote
Accepted
Disable webedit for sc_field in Scriban?
If you have a multi-line text field with multiple lines in it, lines in the value of the field are separated with \r\n line endings. When you render them in html, they will never convert automatically ...
1
vote
How to link static image asset from SXA using scriban
You probably resolved this already - but just in case you still have it hard coded and want to fix it.
Use the sc_query function to retrieve your image using the Sitecore ID of the media item.
The ...
1
vote
Accepted
Is there a way to parse Sitecore DateTime field type value in a particular Date or Time format directly in Scriban?
Scriban has some nice date functions built in so you can use those. Unfortunately, Sitecore stores the raw value as yyyMMddThhmmssZ - so 20210709T102600Z for example. This is not a valid format for C#'...
1
vote
Sitecore container with variants to change background color
If the only difference is the background color I would say follow this guide to handle the styling difference with a checkbox in the properties of a rendering:
Add a style for a rendering
Scriban ...
1
vote
Accepted
Pipe expression destination `string.empty` is not a valid function
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/...
1
vote
Accepted
Sitecore scriban how to fetch linked item from it's linked sub item?
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 ...
1
vote
Accepted
Re-use the scriban template
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
scriban × 45sxa × 36
sitecore-client × 1
link-manager × 1
sxa-search × 1
components × 1
sxa-storefront × 1
css × 1
wildcards × 1
accessibility × 1