Some custom tags support variables as parameter values, enabling some cool tricks, especially when combining it with Data objects.
{% assign count = page.data.count %}
{% for i in (1..count) %}
...
{% endfor %}
Expanding on this, you can use the Settings Editor to create a simple interface to choose how many columns are rendered. The number of columns is saved to page.data and used to render the content areas in the layout.In cases where there are multiple blog pages on one site, it might be useful to show a specific blog's articles on the front page, for example. Now, if the site is multilingual, you would need to know the page.path
in each language. Instead of this, you can use page.data to set a boolean for those specific blog pages and then find the blog that has that data attribute set to true, making it unnecessary to hardcode any paths to the template code.
{% assign featured_blog_path = '' %}
{% for blog in site.blogs %}
{% if blog.data.featured %}
{% assign featured_blog_path = blog.path %}
{% break %}
{% endif }
{% endfor %}
{% blogcontext featured_blog_path %}
{% for featured_article in articles %}
...
{% endfor %}
{% endblogcontext %}
Together with the filtering syntax, variables can be used to generate dynamic element lists. For example, let's say you have a complex page structure with nested category pages that contain elements:
{% elementscontext edicy_model="Products" q.page.path.$starts=page.path %}