Helpers
Your .liquid
files have access to all the standard Liquid tags and filters plus the following ones from Yass.
Variables
page
An object representing the current page. Properties:
title
A titleized version of the filename (e.g. My File from my-file.html), or from YAML front matterlayout
Name of the page’s layout (if any), e.g. default.htmlsrc_path
Path with the original filename (e.g. foo/bar/zorp.md.liquid)path
URL path relative to the relative root (e.g. foo/bar/zorp.html)dirname
Directory file is in (e.g. foo/bar from foo/bar/zorp.html)filename
Name of file (e.g. zorp.html from foo/bar/zorp.html)extname
File extension (e.g. .html from foo/bar/zorp.html)filesize
Size of file in bytespublished
If the file is published or not- Any other value defined in the file’s YAML front matter
<h1>{{ page.title }}</h1>
files
Any array of all (published) files that will be written dist/
. Same properties as page
.
{% assign css_files = files | where: "extname", ".css" %}
{% for file in css_files %}
<link rel="stylesheet" href="{{ file.path | relative }}">
{% endfor %}
Filters
relative
Modifies a path to be relative to the current file. Useful in layouts and template that need to refer to other files.
<script src="{{ "assets/main.js" | relative }}"></script>
If the above HTML was in a/b/c.html.liquid
, the script source would be ../../assets/main.js
.
strip_index
Removes trailing index.html
s from URLs, on the assumption that web servers will handle that. Can be disabled with the --no-strip-index
option (useful for development builds).
<a href="{{ "posts/index.html" | relative | strip_index }}">Posts</a>
match
Returns true if the string matches the regex.
{% assign is_asset = page.path | match: "\.(css|js|jpe?g)$" %}
where_match
Works like Liquid’s built-it where
, but accepts a regular expression.
{% assign posts = where_match: "path", "^posts/.+\.html$" %}
where_not
Works like Liquid’s built-it where
, but returns object that don’t match.
{% assign posts = where_not: "hidden", true %}
Tags
highlight
Converts the given code into something useable by Highlight.js.
{% highlight ruby %}
puts "Yass!"
{% endhighlight %}
Hightlight.js CSS and JS files with common languages are included by default with yass init
. Download your own versions if you want different languages or themes.
render_content
Renders a template, passing the block as a variable named content
.
The following will render the template templates/my_template.liquid
:
{% render_content "my_template" %}
<p>This will be rendered inside of "my_template" from a variable called "content"</p>
{% endrender_content %}