Highlighting liquid code in a liquid template with Jekyll (Escape a liquid templating tag)

Stamped: 25 Aug 2010 | Show comments

This is a somewhat confusing thing to achieve, highlighting liquid templating code in a code block, and made even more confusing by the title. Take this example from this article about I wrote about mephisto:

#previous link
{% if article.previous? %}
  {{article | previous_article | link_to_article }}
{% else %}
  <a href="/">home</a>
{% endif %}

To actually display the liquid template code you have to get crazy with the curly brackets; the code in the markdown (in my case) file actually looks like:

#previous link
{{ “{% if article.previous? “}}%}
    {{ “{{article | previous_article | link_to_article  “}}}}
{{ “{% else “}}%}
  <a href="/">home</a>
{{ “{% endif “}}%}

Typing that above leads to a sweet infinity effect, but do yourself a favor and don't copy/paste that, just take it from this post on github, because to actually type that I had to use &ldquo;. Of course a proper way to do would be to extend markdown/textile in pygments to support the liquid templating language, but that's for another day.

tags: liquid, jekyll
recent entries
Rails — A faster way for next and previous links on a post, article, or any model
The awkward things Siri says
Node.js — Getting oAuth Up and Running Using Express.js and Mongoose
Node.js — Getting oAuth Up and Running Using Express.js, Railway.js and Mongoose
Migrating from Rails 3.1 RC4 to RC5 using Heroku's Cedar Stack (also compass, unicorn, and sendgrid)
Random Freeze Fix for GTX 460 in 10.6 (osx86)
Wasted on Steam - an analytic tool for the Steam platform
Rails 3.1 — SQL logging to STDOUT during testing (with rspec, test::unit, or cucumber)
Rails 3.1 — Using ERB/HAML/etc within a Coffeescript JS file
Rails 3.1 — 'load_missing_contant': Expected ... to define ... (LoadError)
View the entire archive of articles