~adnano/kiln-discuss

1

Adding custom functions

Details
Message ID
<CL2JBDQS1ZBP.1IBD297ZB6TQ0@henleybeach>
DKIM signature
pass
Download raw message
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?
Details
Message ID
<CL2LBOAOQHD4.SVKW73W8112I@nitro>
In-Reply-To
<CL2JBDQS1ZBP.1IBD297ZB6TQ0@henleybeach> (view parent)
DKIM signature
pass
Download raw message
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.
Reply to thread Export thread (mbox)