What template format/dialect/engine do Klaviyo templates use?

56 Views Asked by At

You can download the raw templates via Klaviyo's API, but how to render them once we have them so as to avoid having to implement that parsing ourselves? It looks like Jinja2.

Their APIs only support one-at-a-time rendering, so it's not possible to use their API for this task at scale.

1

There are 1 best solutions below

0
Dustin Oprea On

Close. It seemingly uses Django. There are no references anywhere except for this implication from the page with the list of supported filters:

https://developers.klaviyo.com/en/docs/glossary_of_variable_filters

enter image description here

For convenience, the code to render a template (via Python) while loading the bare minimum of the Django project with no configuration requirement:

#!/usr/bin/env python3

import django.template
import django.template.engine

def _main():
    e = django.template.engine.Engine()

    body = """\
aa {{ test_token }} cc
"""

    t = django.template.Template(body, engine=e)

    context = {
        'test_token': 'bb',
    }

    c = django.template.Context(context)
    r = t.render(c)

    print(r)


_main()

Output:

$ ./test_render.py 
aa bb cc