Inserting Liquid Syntax Into Octopress Codeblock

The not entirely reliable trick I’ve found for inserting liquid code into an Octopress codeblock is to double wrap your code with [% codeblock %] [% raw %] ... [% endraw ] [% endcodeblock %]. But use curly brackets { } instead of square brackets [ ]. I can’t use the curly brackets because if I do they bugger up the codeblock below.

Here is sample output when I double wrap with codeblock and raw.

1
2
3
4
5
6
7
8
9
---
layout: page
title: "Product Page - Title will be replaced by generator plugin"
---

<p>{{ page.product.description }}</p>
<p><strong>Ingredients: </strong>{{ page.product.ingredients }}</p>
<p>{{ page.product.size }}</p>
<p>{{ page.product.price }}</p>

The alternative is to farm your code snippets out to a separate file.

Let me know if you’ve found a better way of doing this.

Comments