Skip to content

Instantly share code, notes, and snippets.

@sixones
Created March 12, 2009 09:59
Show Gist options
  • Save sixones/77982 to your computer and use it in GitHub Desktop.
Save sixones/77982 to your computer and use it in GitHub Desktop.
Liquid Cheatsheet
Liquid for Mephisto Cheatsheet
Compiled by Lee Leonard
Version 0.2 - 31 Jan 2007 (liquid 1.5.0; Mephisto 0.7.3)
This is a second draft -- corrections and suggestions are even more
encouraged. Send them to <l...@tempestprod.com>.
Basic Syntax
{{ (variable | string) ['|' filter1 ['|' filter2...]] }}
{% controltag %} [..] {% endcontroltag %}
Simple Example: -- show main sections w/no subsections
{{ '' | child_sections | assign_to: 'main_sections' }}
<ul>
<li>{{ site.home_section | link_to_section }}</li>
{% for each_section in main_sections %}
<li>{{ each_section | link_to_section }}</li>
{% endfor %}
</ul>
Built-In Filters
capitalize
date[: '%A, %d.%m.%y'] -- see Date Formats below
downcase
first
join[: glue=' ']
last
size
sort
strip_html
truncate[: length=50 [, truncate_string="..."]]
truncatewords[: words=15 [, truncate_string="..."]]
upcase
Built-In Control Tags
{% assign: alias = variable %}
{% capture: 'var_name' %}
[..] -- any text or vars
{% endcapture %}
{% case variable %}
{% when 'option1' %} [..]
{% when 'option2' %} [..] ...
{% else %} [..]
{% endcase %}
{% comment %} [..] {% endcomment %}
{% cycle ['group']: 'option1', 'option2'... %}
{% for variable in array [offset: (number | continue)] [limit:
number] %}
[..]
forloop.length
forloop.index
forloop.index0
forloop.rindex
forloop.rindex0
forloop.first
forloop.last
{% ifchanged %} [..] {% endifchanged %}
{% endfor %}
{% if condition %} [..] {% else %} [..] {% endif %}
{% include 'template' [(with | for) (object | collection)] %}
-- templates/template.liquid
{% tablerow variable in array [cols: number] [offset: (number |
continue)] [limit: number] %}
[..]
[forloop variables available]
{% endtablerow %}
{% unless condition %} [..] {% else %} [..] {% endunless %}
Mephisto Utility Filters
assign_to: "var_name"
assign_to_global: "var_name"
escape_html
h -- aka escape_html
index[: index = 0]
format_date: format[, ordinalized = false]
parse_date
pluralize: singular[, plural=nil]
strftime: format -- see Date Formats below
textilize
word_count
Mephisto Control Tags
{% commentform %}
form.name
form.email
form.url
form.body
form.submit
{% endcommentform %}
Mephisto Filters by Input
Article
changes_feed[: title = nil]
comments_feed[: title = nil]
link_to_article[: text = nil]
link_to_comments[: text = nil]
linked_section_list[: separator = ', ']
Page
?link_to_page[: section = nil, text = nil]
?page_url[: section = nil]
Section
archive_url: *pieces
articles_feed[: title = nil]
comments_feed[: title = nil]
latest_article
latest_articles[: limit = nil]
latest_comments[: limit = nil]
link_to_month[: date = nil, format = 'my']
link_to_section[: text = nil]
monthly_articles[: date = nil]
monthly_url[: date = nil]
Site
find_section[: path]
find_child_sections[: path]
find_descendant_sections[: path]
latest_articles[: limit = nil]
latest_comments[: limit = nil]
String
all_comments_feed -- input: title
assets_by_type -- input: type
asset_url -- input: asset
atom_feed[: title = nil] -- input: url
child_sections -- input: path
descendant_sections -- input: path
img_tag[: options = {}] -- input: img_url
javascript -- input: js_name - .js
javascript_url -- input: js_name - .js
link_to_tag -- input: tag
search_url[: page = nil] -- input: query
section -- input: path
stylesheet[: media = nil] -- input: css_name w/o .css
stylesheet_url -- input: css_name w/o .css
tag_url -- input: tag
tagged_articles -- input: tag
tagged_assets -- input: tag
Mephisto Drops
content_for_layout -- layout.liquid
Article.author
" .blog_sections
" .changes_feed_url
" .comments
" .comments_allowed
" .comments_feed_url
" .comments_count
" .content
" .excerpt
" .id
" .page_sections
" .permalink -- relative url
" .published_at
" .sections
" .tags
" .title
" .updated_at
" .url -- absolute url
Asset.content_type
" .filename
" .height
" .path
" .size
" .tags
" .width
Comment.author
" .author_email
" .author_ip
" .author_link
" .author_url
" .id
" .presentation_class
" .title
" .url
Section.archive_path
" .articles
" .comments
" .current
" .id
" .earliest_month
" .latest_articles
" .latest_comments
" .months
" .name
" .pages
" .path
" .url
Site.articles_per_page -- "site." optional
" .blog_sections
" .current_section
" .find_section(path)
" .find_child_sections(path)
" .find_descendant_sections(path)
" .home_section
" .host
" .id
" .latest_articles(limit = nil)
" .latest_comments(limit = nil)
" .page_sections
" .search_path
" .sections
" .subtitle
" .tag_path
" .tags
" .title
User.email
" .login
Mephisto Layouts (found in mephisto/themes/site-1/theme_name)
layouts/layout.liquid -- wrapper for theme
templates/_comments.liquid
templates/_page.liquid
templates/_shared.liquid
templates/archive.liquid
templates/error.liquid
templates/home.liquid
templates/search.liquid
templates/section.liquid
templates/single.liquid
templates/tag.liquid
Date Formats
%a - The abbreviated weekday name ("Sun")
%A - The full weekday name ("Sunday")
%b - The abbreviated month name ("Jan")
%B - The full month name ("January")
%c - The preferred local date and time representation
%d - Day of the month (01..31)
%H - Hour of the day, 24-hour clock (00..23)
%I - Hour of the day, 12-hour clock (01..12)
%j - Day of the year (001..366)
%m - Month of the year (01..12)
%M - Minute of the hour (00..59)
%p - Meridian indicator ("AM" or "PM")
%S - Second of the minute (00..60)
%U - Week number of the current year,
starting with the first Sunday as the first
day of the first week (00..53)
%W - Week number of the current year,
starting with the first Monday as the first
day of the first week (00..53)
%w - Day of the week (Sunday is 0, 0..6)
%x - Preferred representation for the date alone, no time
%X - Preferred representation for the time alone, no date
%y - Year without a century (00..99)
%Y - Year with century
%Z - Time zone name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment