We are using SXA Rendering Variants
with Scriban
for our websites. In order to format the value of Sitecore field type DateTime in Scriban I am using
`{{ sc_field i_item 'Date' [ [ 'format', 'd\nM,\nyyyy' ] ] }}` .
This works fine if the value is between the tags like below
<module-headline block="text-content">
{{ sc_field i_item 'EventDate' [ [ 'format', 'd\nM,\nyyyy' ] ] }}
</module-headline>
<!-- OR display: block -->
<module-subline>{{ sc_field i_item 'EventDate' [ [ 'format', 'd\nM,\nyyyy' ] ] }}</module-subline>
But if I try to use this in one of the properties of the tags or with in JSON object in Scriban it does not work.
<sticky-detail-module
date="{{ sc_field i_item 'EventDate' [ [ 'format', 'd\nM,\nyyyy' ] ] }}"
place="{{ chosenevent.EventLocationLong.raw }}"
button-url="{{ sc_linktargeturl chosenevent 'Button1' }}"
button-text="{{ chosenevent.Button1Text.raw }}"
>
</sticky-detail-module>
OR WITH
<events-teaser
:events="[
{
'place':'Barcelona',
'date':'{{ sc_field i_item 'EventDate' [ [ 'format', 'd\nM,\nyyyy' ] ] }}',
'title':'Headline',
'summary':'120 letters description – Lorem ipsum dolor sit amet, consetetur sadipscing elitr.',
'image':'../1920x1080.png',
'alt':'main events image',
'button2Text':'More information',
'button1Text':'Buy tickets',
'button2Url':'https://www.google.com/',
'button1Url':'https://www.google.com/'
},
{
'place':'Barcelona',
'date':'{{ sc_field i_item 'EventDate' [ [ 'format', 'd\nM,\nyyyy' ] ] }}',
'title':'Headline',
'summary':'120 letters description – Lorem ipsum dolor sit amet, consetetur sadipscing elitr.',
'image':'../1920x1080.png',
'alt':'main events image',
'button2Text':'Text 2',
'button1Text':'Text 1',
'button2Url':'https://www.google.com/',
'button1Url':'https://www.google.com/'
},
]">
</events-teaser>
Is there a way to parse Sitecore DateTime field type value in a particular Date or Time format directly in Scriban for the tag properties as well? Is custom Embedded functions the only way to achieve this formatting?