Using Scriban to wrap a span inside an an anchor

On a recent project I had my first foray into using Scriban templates with Sitecore SXA. If you aren't familiar Scriban is a billed as:
Scriban is a fast, powerful, safe and lightweight text templating language and engine for .NET, with a compatibility mode for parsing liquid templates.
A little background, fir this project we have a Sitecore template called Icon setup like so:

The Icon field links to a predefined list of items which are all based on the OOTB SXA Style template. Each Style just stores a class name e.g. fa-facebook-square in the Value field.

We will be using the list of Icons to create links in the footer like so:

I needed to whip up a Scriban template to generate the following markup for each item in a list based on that template:

It took me a bit, but I finally figured out you can mix static values and Scriban function calls together. Seems simple but it wasn't obvious (to me) in the offical documentation.

To do so you wrap your embedded Scriban function calls in ( ) and concat it all together like any other language with the +.

Here we:
  • Call sc_field
  • Pass in the current item (which is based on the Icon template) i_item 
  • Pass in the field we want to render, 'Link'
    • Since Link is a General Link sc_field will generate an anchor tag
  • Passing in an optional parameter [['text', ... ]]
    • We want to set the text of the anchor to a span with a specific class, the class we want is stored in the field 'Value' of the Icon (which is just an enum)
  • Inside the [['text', ...)]] we call sc_follow by wrapping it in ( ) and pass in the current item (i_item) and the field we want to "follow", Icon
  • Then we pipe in another function sc_field and pass in the name of the field we want "Value"

We end up with:

Seems simple NOW but I was banging my head on that one and thought I'd share.


  1. Lucky Club Casino Site Review 2020 - LuckyClub Live
    Lucky Club Casino was founded in 2017 by the developers of the Microgaming gaming software, Playtech. Read our complete review. Rating: 5 · ‎Review by LuckyClub

  2. Harrah's Cherokee Casino Resort - MapYRO
    Property LocationWith a 전라남도 출장마사지 stay at Harrah's Cherokee Casino Resort in Murphy, 양산 출장안마 you'll be centrally located 원주 출장샵 in the Great Smoky 계룡 출장안마 Mountains of Western North Carolina. Rating: 4.5 · ‎17 포천 출장마사지 reviews

  3. Spin away on prime slots like Zeus III, Elvis The King Lives, Montezuma, Pirates Millions, Ultimate Universe and Panda Manga. Personalizing your username is necessary and when you close this popup, you will have to|you'll have to} begin over with the login course of. You are leaving and going to the web site} of our trusted supplier. Please 카지노 return to to learn more about different advantages. AARP is a nonprofit, nonpartisan organization that empowers people choose on} how they stay as they age.

  4. — Punters in North Korea who as soon as} risked three years exhausting labour for playing second are|are actually} able to to} guess on native horse races as the isolated nation scrambles to unearth new sources of exhausting forex amid intensifying worldwide sanctions. Recently, the KFTC has initiated an investigation in opposition to a significant Korean gaming firm regarding loot bins. The KFTC has a history of enforcing sanctions for unfair enterprise practices, including false or deceptive promoting.

  5. We concentrate on fabrication and supply of structural and miscellaneous projects as much as} 2,000 Tons built to AISC Standards with both quality and efficiency to meet our purchasers demanding schedules. Direct CNC Discover innovation and know-how options at FABTECH®, North America’s largest metallic forming, fabricating, welding, and ending occasion. Help the muse of FMA ensure method ahead for} metallic manufacturing by engaging and supporting the industry’s brightest minds. Be a part of|part of} an affiliation that's dedicated to helping trade professionals succeed and advance metallic fabrication.


Post a Comment