Octopress Return Tag
Render Liquid variables with conditions and filters.
Installation
Add this line to your application's Gemfile:
gem 'octopress-return-tag'
And then execute:
$ bundle
Or install it yourself as:
$ gem install octopress-return-tag
Next add it to your gems list in Jekyll's _config.yml
gems:
- octopress-return-tag
Usage
Here's a simple example where you can see that it does the same thing as the standard liquid render braces.
{{ site.author }} //=> Bobby Tables
{% return site.author %} //=> Bobby Tables
{{ site.author | upcase }} //=> BOBBY TABLES
{% return site.author | upcase %} //=> BOBBY TABLES
Conditional returns.
{% return "→ " if linkpost %}
{% return "★ " unless linkpost %}
{% return post.external-url || post.url %}
{% return (post ? post.date : page.date ) | datetime | date_to_xmlschema %}
Why is this useful? Here's how you might add title markers for a linkpost blog.
{% return (linkpost ? "→ " : "★ ") %}{{ post.title }}
Now here's what you'd have to do with standard liquid tags:
{% if linkpost %}
{% capture title %}→ {{ post.title}}{% endcapture %}
{% else %}
{% capture title %}★ {{ post.title }}{% endcapture %}
{% endif %}
{{ title }}
See how if
and capture
make it harder to read a template file? That's why the return tag exists.
Contributing
- Fork it ( https://github.com/octopress/return-tag/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request