Trigger templating engine Jinja2 from button

Hello,
I’d like to use jinja2 for templating some fields like description/title…
And I’d like to trigger the generation of these texts from a button in case I’am not ok with the default value , is it possible ?
and being able to use these keywords inside :
#random
#safe
#capitalize
#lower
#upper
#title
#trim
#striptags

2 Likes

Hi @Sao,

There isn’t yet a way to include third-party libraries in formulas, and jinja2 in particular isn’t included into the formula engine. So this isn’t yet possible. We are considering adding a way to add extra libraries, but no ETA yet.

What I can suggest that’s similar is to use native Python templating, i.e. with a formula like:

'Hello {first} {last} from {company}!'.format(
    first=$First_Name, last=$Last_Name, company=$Company.upper())

It doesn’t let you modify the variables (like capitalizing), but you can do that outside the template string as in this example.

If you’d like to be able to override these values, there are a couple of options:

  1. Just have both the calculated template and your override (that’s normally empty), and a final result with a formula like $Override or $Template (returning $Override when it’s non-empty, otherwise returning $Template).

  2. Use trigger formulas. There aren’t buttons (yet) to trigger regeneration, but you can simulate it with a Toggle column. Call this toggle “Regenerate”, and make set the formatting formula as a trigger formula that triggers for new records and for changes to the “Regenerate” column. To recompute, click “Regenerate” – it’ll toggle on or off, but its state doesn’t matter, only the fact that it changes, which will cause the trigger formula to update. And if you edit the resulting value directly, it’ll stick (until you click “Regenerate”, of course).

1 Like

Merci beaucoup :heart_eyes:.
For the self hosted version, we cannot install third-party libraries too ?

You do have more flexibility in self-hosted. Specifically, the file sandbox/requirements3.txt lists the third-party libraries (which get installed by running yarn run install:python). This should work with any of the sandboxing options for the Python data engine, as long as you have Python 3 on your system.

2 Likes

thank you very much for the suggestions :wink:
is it possible instead of having the empty column to override it,
a column with the template computed and if I want to edit it, it would be easier than copying from the template and paste it on the “override” column for edition
and then "final result " would be in a column with the formula checking if there is any difference between them , so if any changes, it’s gonna be the override otherwise the original template

Thanks :smile: