How can I write/invoke a custom Liquid Tag with two parameters?
Context: Jekyll 2.1.1
I have some pages that are presented as a tab set. My page front matter is allowed to define extra tabs for some pages, like this:
---
blah: blah
extra-tabs:
- A page: a-page.md
- Another page: other-page.md
---
I can solve this thanks to Iterate over hashes in Liquid Templates. But ...
I have an additional constraint: when rendering a-page.md, the tab displayed should look different (<li class="active">...). While this can be solved by the techniques linked above, it's ugly:
{% for extra_tab_hash in page.extra-tabs %}
{% for extra_tab in extra_tab_hash %}
{% if page.name == extra_tab[1] %}
<li class="active"><a href="#">{{extra_tab[0]}}</a></li>
{% else %}
<li><a href="{{ extra_tab[1] | in2out }}">{{extra_tab[0]}}</a></li>
{% endif %}
{% endfor %}
{% endfor %}
I would like to write a custom tag that replaces the conditional if/else/endif, something like:
{% for extra_tab_hash in page.extra-tabs %}
{% for extra_tab in extra_tab_hash %}
{% mytab extra_tab[0] extra_tab[1] %}
{% endfor %}
{% endfor %}
I have two problems there:
- mytab is receiving only one input, conventionally called text, containing all the stuff inside the {% ... %}, whereas I need two separate values. I could have the Tag split(',') or something, but there's this other problem?
- it's not interpreted: it's literally "extra_tab[0] extra_tab[1]".
So: How can I induce Liquid to expand the references to "extra_tab[*]"?