Is there a way to maintain libraries of our own functions for use in the email templates?
“Don’t Repeat Yourself” (DRY) is an important programming principle, but our templates are built with a lot of cut-and-paste snippets.
For example, we frequently use:
{{ person|lookup:"VehicleModel"|default:'ride' }}
...to say things like “new items for your Toyota Tundra”. This is sprinkled through a great many templates.
The right way to do this is with a function, something like:
def getVehicle(person)
# return person|lookup:"VehicleModel"|default:'ride'
person.fetch("VehicleModel", "ride")
end
...and then just
{{ getVehicle(person) }}
in the template itself. It’s short, simple, reusable.
is this syntax, or something like it, possible? Ruby, Python, Javascript - I don’t care which, any reasonable language will do. And can functions be placed into a file to be shared and reused across all our templates?