A port of liquid template engine for python
pip install liquidpy
- Note that this branch is not fully compatible with shopify's liquid. For compatible versions, please check branches lark and larkone.
- This branch is current NOT safe agaist malicious input (#22), so we tried to re-implement the engine using
lark-parser
. However, both versions were very slow for lexer. - With branch
lark
, we tried to tokenize each tag and parse the content of the tags later using independent parsers, while withlarkone
, we tried to put all grammars together, and made it into a universal parser. However, both of them are slow, due to tokenization of whole tags (raw
andcomment
) and literals (Seegrammar.lark
in the code). - If you have a better grammar or idea for tokenization, you are very welcome to submit issues or PRs (writing naive lexer is just too much work).
- We left some APIs to extend the
lark
ones with some functions frommaster
. However, it won't happen before we find a faster lexer. - A temporary plan for the
master
branch is to do some security check to address #22.
from liquid import Liquid
liq = Liquid('{{a}}')
ret = liq.render(a = 1)
# ret == '1'
# load template from a file
liq = Liquid('/path/to/template', liquid_from_file=True)
With environments:
liq = Liquid('{{a | os.path.basename}}', os=__import__('os'))
ret = liq.render(a="path/to/file.txt")
# ret == 'file.txt'