Skip to content

Latest commit

 

History

History
96 lines (70 loc) · 3.24 KB

README.rst

File metadata and controls

96 lines (70 loc) · 3.24 KB

liquidpy

A port of liquid template engine for python

` .. image:: https://img.shields.io/pypi/v/liquidpy.svg?style=flat-square

target:https://img.shields.io/pypi/v/liquidpy.svg?style=flat-square
alt:Pypi

<https://pypi.org/project/liquidpy/>`_ `

https://img.shields.io/github/tag/pwwang/liquidpy.svg?style=flat-square:target:https://img.shields.io/github/tag/pwwang/liquidpy.svg?style=flat-square:alt:Github<https://github.com/pwwang/liquidpy>`_`

https://img.shields.io/pypi/pyversions/liquidpy.svg?style=flat-square:target:https://img.shields.io/pypi/pyversions/liquidpy.svg?style=flat-square:alt:PythonVers<https://pypi.org/project/liquidpy/>`_`

https://img.shields.io/codacy/grade/aed04c099cbe42dabda2b42bae557fa4?style=flat-square:target:https://img.shields.io/codacy/grade/aed04c099cbe42dabda2b42bae557fa4?style=flat-square:alt:Codacy<https://app.codacy.com/manual/pwwang/liquidpy/dashboard>`_`

https://img.shields.io/codacy/coverage/aed04c099cbe42dabda2b42bae557fa4?style=flat-square:target:https://img.shields.io/codacy/coverage/aed04c099cbe42dabda2b42bae557fa4?style=flat-square:alt:Codacycoverage<https://app.codacy.com/manual/pwwang/liquidpy/dashboard>`_

Docs building Building

This is compatible with standard Liquid template engine. Variations, such as Shopify and Jekyll are not fully supported yet.

Install

pip install -U liquidpy

Baisic usage

from liquid import Liquid
liq = Liquid('{{a}}')
ret = liq.render(a=1)
# ret == '1'

# with environments pre-loaded
liq = Liquid('{{a}}', a=1)
ret = liq.render()
# ret == '1'

# With debug on:
liq = Liquid('{{a}}', liquid_config={'debug': True})

Python mode

We also support a python mode template engine, which acts more pythonic and powerful.

from liquid import Liquid
# standard liquid doesn't support this
liq = Liquid('{{a + 1}}', {'mode': 'python'})
ret = liq.render(a=1)
# ret == '2'

Both modes can accept a path, a file-like object or a stream for the template:

Liquid('/path/to/template')
# or
with open('/path/to/template') as f:
    Liquid(f)

Full Documentation

Backward compatiblility warning

v0.6.0+ is a remodeled version to make it compatible with standard liquid engine. If you are using a previous version, stick with it. 0.6.0+ is not fully compatible with previous versions.