I'd like to add a modulus operator to my templates so that I can
perform a range over a data structure and have it behave differently on
odd and even elements. I've read the manpage on the `call` function,
which I believe should be able to help me add a custom function, but I
don't understand what it's supposed to be doing.
Would you help me understand how to achieve this?
On Wed Jun 29, 2022 at 6:09 AM EDT, Edd Salkield wrote:
> I'd like to add a modulus operator to my templates so that I can
> perform a range over a data structure and have it behave differently on
> odd and even elements. I've read the manpage on the `call` function,
> which I believe should be able to help me add a custom function, but I
> don't understand what it's supposed to be doing.
>
> Would you help me understand how to achieve this?
There isn't an easy way to define custom functions without patching and
recompiling kiln itself. However, you can stick reusable template pieces
into a partial template and use it from other templates.
The 'call' function is a built-in Go template function which simply
allows you to call existing methods, but it is largely redundant as you
can use dot notation to call them.