Developing Liquid Template Language Filters in Orchard Core CMS

Caesar Cipher Filter to create secret messages :)

Orchard Core CMS support the Liquid Template Language developed by Shopify for its e-commerce stores. At least 2 of the themes that come with Orchard Core (at least as of beta 2) use the Liquid Template Language instead of the Razor Template Language. Inspired by this I developed 3 custom themes that also use Liquid, and on this rainy Sunday at Starbucks, I developed a custom Orchard Core Module that creates a custom Liquid Template Language Filter! Yes, we have the ability to create custom filters for the Liquid Template Language in Orchard Core!

Liquid Template Language Filters

Once you create a Custom Orchard Core Theme or use the Liquid Widgets and Liquid Pages you will become familiar with Liquid Filters. For example, to display the title of a ContentItem in Orchard Core using Liquid you would use the display_text filter.

{{ Model.ContentItem | display_text }}

If you want to slugify a piece of text in Orchard Core, you would use the slugify filter.

{{ "some text i want to slugify" | slugify }}

I believe Orchard Core supports all the filters that are built into liquid as well as adds custom filters. As an Orchard Core Developer, one can also develop his/her own custom liquid filters.

Caesar Cipher Liquid Template Language Filter

This past year I taught Python to budding new developers and one of the projects as part of a "hacking" day was to encipher and decipher the substitution cipher, Caesar Cipher. Inspired by how much fun I had teaching programming, I created a custom liquid filter for Orchard Core that enciphers a body of text using Caesar Cipher.

Orchard Core Module adding Liquid Template Language Filter

Using the liquid filter in a theme, widget, or page is just as you would expect. If we want to use a right shift of 23 as a key,

{{ "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG" | caesar: key:23 }}

the following cipher text will be displayed on the Orchard Core Website using Caesar Cipher with a right shift of 23.

QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD

The key is optional. By default it will use 3, which I believe Julius Caesar is known for using in his private correspondence.

{{ "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG" | caesar }}

The following cipher text will be displayed.

WKH TXLFN EURZQ IRA MXPSV RYHU WKH ODCB GRJ

This is a playful use of developing custom Liquid Template Language Filters for Orchard Core. However, when you develop custom modules for Orchard Core you may want to create liquid filters to expose that functionality.

Not bad for a relaxing Sunday afternoon at Starbucks!