I am trying to create a tag plugin that loops, like the Liquid {% for %}
tag.
So one could do something like:
{% counter 3 %}
Going {{ counter }} time...
{% endcounter %}
To produce:
Going 1 time...
Going 2 time...
Going 3 time...
I’d like to do this with native for loop/context variable evaluation logic, rather than a hack.
One can’t just do a find/replace on {{ placeholders }}
in the block body, as the block body is already sent to the tag with anything in double-curly-braces evaluated.
So you could hack it by inventing your own syntax, e.g. << placeholder >>
, but this is just really dirty.
I’ve tried pasting the code of the actual Liquid For tag into my own plugin, but this won’t run. I get undefined method 'render' for nil:NilClass
.
Does anyone understand how the for loop tag works well enough to help me out in creating my own looping tag? Thanks.