stencilproject / Stencil

Stencil is a simple and powerful template language for Swift.
https://stencil.fuller.li
BSD 2-Clause "Simplified" License
2.33k stars 221 forks source link

Question: Is there a way to nest tags #311

Open otusweb opened 2 years ago

otusweb commented 2 years ago

I'm trying to create a stencil for a document that consists of two columns and where I want the left column to be left justify and the right column right justified. ie:

abcd     efgh
abc       fgh
abcd     efgh
abc       fgh 

I could write a custom tag that would take the width of the page and the two parameters and this would work fine. The problem I run into is that each string would itself need to be a tag/variable (the left side are localised strings, the right side is data coming from app.

Any idea on how to do this?

djbe commented 1 year ago

I don't see why the parameters of your tag/filter/… can't be variables. See for example the for tag, it accepts both constants & variables:

{% for item in myArray %}…{% endfor %}

{% for item in 1...3 %}…{% endfor %}

So if you have a custom tag, you could accept multiple parameters, mixes of constants and variables. See the call tag in StencilSwiftKit:

{% call myMacro "myString" myVariable "someOtherString" %}