Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Created December 24, 2019 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save james2doyle/dfd5af3251151fbfceb8d52b84d54538 to your computer and use it in GitHub Desktop.
Save james2doyle/dfd5af3251151fbfceb8d52b84d54538 to your computer and use it in GitHub Desktop.
An example of most of the things you can do in Liquid (Shopify). Used for building syntax highlighting
Hello {{ 'tobi' | upcase }}
Hello tobi has {{ 'tobi' | size }} letters!
Hello {{ '*tobi*' | textilize | upcase }}
Hello {{ 'now' | date: "%Y %h" }}
{% if string contains 'hello' %}
string includes 'hello'
{% endif %}
{% for item in collection reversed %} {{item}} {% endfor %}
{% for i in (1..item.quantity) %}
{{ i }}
{% endfor %}
{% cycle 'one', 'two', 'three' %}
{% case template %}
{% when 'product' %}
{{ product.vendor | link_to_vendor }} / {{ product.title }}
{% else %}
{{page_title}}
{% endcase %}
{% liquid
echo 'sup?' %}
{% for item in items %}
{{ item }}
{% endfor %}
{% if freestyle %}
<p>Freestyle!</p>
{% endif %}
{% render 'something', variable: value %}
{% capture attribute_name %}
{{ item.title | handleize }}-{{ i }}-color
{% endcapture %}
{% raw %}
You can see this is not highlighted the same as {{ before | escape }}
{% endraw %}
{% schema %}
{
"name": "Slideshow",
"settings": [
{
"id": "header",
"type": "text",
"label": "Header",
"default": "Hello world"
}
]
}
{% endschema %}
{% stylesheet %}
body {
color: white;
background-color: black;
}
{% endstylesheet %}
{% stylesheet 'scss' %}
body {
color: rgba(#fff, 0.2);
p {
margin: 0;
}
}
{% endstylesheet %}
{% javascript %}
const item = ['value', 1, false, null];
item.map(i => i.toLowerCase());
{% endjavascript %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment