3

In SXA 9.3 we have the possibility of using Scriban Templates. I wonder if there is a possibility to use Sitecore rules engine inside of those templates. Let say that I would like to render part of template only if my context item meets certain rule.

Is this possible?

1 Answer 1

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:

enter image description here

And the rule looks like this:

enter image description here

That is pretty it! The sc_evaluate i_item "DayOfWeek" in the if statement will evaluate the "DayOfWeek" rule against context item and base on this will render the Brand field or not.

If you would like to evaluate the rule against other embedded objects (e.g.: data source item) the list of those you will find here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.