Sitecore scriban for language dropdown
We using scriban template to load language selector for the website , as not using out of box SXA language selector, we need more control from content author side.
We have template with language multilist field , so that the content author have control to select or deselect the languages as per their wish.
Scriban template to load language selector:
- Loop through all the languages content author selected from the field "Site Languages" and compare with the context language to make it as active language
- Url will be dynamic based on the language
<ul>
{{ for languages in (sc_followmany i_datasource "Site
Languages" ) }}
{{ itemLanguage=(sc_field languages 'Regional Iso Code') }}
{{itemLanguage=(itemLanguage | string.downcase)}}
{{contextLanguage=(i_datasource.language )|
string.downcase}}
{{if
contextLanguage== itemLanguage }}
<li class="{{sc_field languages 'Iso'}} active"><a
href="{{ (i_page.url | string.downcase) | string.replace ("/" |
string.append ( i_page.language| string.downcase)) ("/" | string.append
((sc_field languages 'Regional Iso
Code') | string.downcase) )
}}">{{ sc_field languages
'Language Name' }}</a></li>
{{else}}
<li class
="{{sc_field languages
'Iso'}}"><a href="{{ (i_page.url | string.downcase)
|string.replace ("/" | string.append ( i_page.language|
string.downcase)) ("/" | string.append ((sc_field languages 'Regional Iso Code') |
string.downcase) )
}}">{{sc_field languages
'Language Name'}} </a></li>
{{end}}
{{end }}
</ul>
Comments
Post a Comment