Object Filters
assign_to
Assign the passed object to a variable name in the local scope.
Expects: Anything
| Argument | Required | Description |
|---|---|---|
| string | required | The variable name to assign |
{{ 'foobar' | assign_to: 'baz' }}
{{ baz | upcase }} # => FOOBAR
assign_to_global
Assign the passed object to a variable name in the global scope.
Expects: Anything
| Argument | Required | Description |
|---|---|---|
| string | required | The variable name to assign |
{% case '/foo/' %}
{% when '/foo/' %}
{{ 'foo' | assign_to_global: 'global_variable' }}
{% when '/bar/' %}
{{ 'bar' | assign_to_global: 'global_variable' }}
{% endcase %}
{{ global_variable }} # => foo
If we had used assign_to in the example above, it would not have worked as it would have assigned to the scope inside the case statement and thus would not work outside case statement.
find_by_label
Find posts from a blog or whole site marked with a given label.
Expects: String (path), Blog, or Site
| Argument | Required | Description |
|---|---|---|
| string | required | The label to find |
| integer | optional | The number of posts to return. Defaults to 10; Limit of 50 |
{{ site | find_by_label: 'featured' }}
{{ 'our-writing/blog' | find_by_label: 'my-label', 5 }}
item_from_path
Get any item object from your site based on its public path.
Expects: String
| Argument | Required | Description |
|---|---|---|
| string | required | The path of the item |
{{ '/' | item_from_path }} # => Your home page item
{{ '/portfolio/featured/' | item_from_path }} # => The item viewable at /portfolio/featured/