-
High @jg-rp, thx for the awesome library you've made 🙌 . Is it possible to generate a Liquid template using the AST? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @axelv, Not currently. If you're looking to build an AST programatically, it would be tricky to implement and fairly horrible to use for all but the most simple of Liquid expressions. Perhaps a builder UI would be needed to make such a thing manageable. If you already have a from liquid import Template
template = Template(
"""\
<head>
<title>{{ site.name }} - {{ page.title }}</title>
</head>
<body>
{% for x in (1..3) %}
<h1>Hello, {{ you }}</h1>
{% endfor %}
</body>"""
)
print(template.tree) output (not valid Liquid)
|
Beta Was this translation helpful? Give feedback.
Correct. It's possible, just fiddly.
Or maybe less fiddly depending on the modifications you need to make. I can imagine custom tag implementations (including custom versions of standard tags) that manipulate AST nodes at parse time rather than trying to change the AST after it's built.