Skip to content

liquid.liquid

module

liquid.liquid

Provides Liquid class

Classes
class

liquid.liquid.Liquid(template, from_file=None, mode=None, env=None, filter_with_colon=None, search_paths=None, globals=None, filters=None, filters_as_globals=None, **kwargs)

The entrance for the package

Examples
>>> Liquid('{{a}}', from_file=False)>>> Liquid('template.html')
Parameters
  • template (PathLike or str) The template string or path of the template file
  • from_file (bool, optional) Whether template is a file path. If True, aFileSystemLoader will be used in the env.
  • mode (str, optional) The mode of the engine.
    • - standard: Most compatibility with the standard liquid engine
    • - jekyll: The jekyll-compatible mode
    • - shopify: The shopify-compatible mode
    • - wild: The liquid- and jinja-compatible mode
  • env (Environment, optional) The jinja environment
  • filter_with_colon (bool, optional) Whether enable to use colon to separate filter andits arguments (i.e. {{a | filter: arg}}). If False, will fallback to use parentheses ({{a | filter(arg)}})
  • search_paths (Union(pathlike, str, iterable of pathlike or str), optional) The search paths for the template files.This only supports specification of paths. If you need so specify encoding and/or followlinks, you should use jinja's FileSystemLoader
  • globals (optional) Additional global values to be used to render the template
  • filters (optional) Additional filters be to used to render the template
  • filters_as_globals (bool, optional) Whether also use filters as globalsOnly works in wild mode
  • **kwargs (any) Other arguments for an jinja Environment construction andconfigurations for extensions
Methods
  • from_env(template, env, from_file, filter_with_colon, filters_as_globals, mode) (Liquid) Initiate a template from a jinja environment</>
  • render(*args, **kwargs) (any) Render the template.</>
  • render_async(*args, **kwargs) (any) Asynchronously render the template</>
method

render(*args, **kwargs) → any

Render the template.

You can either pass the values using tpl.render(a=1) or tpl.render({'a': 1})

method

render_async(*args, **kwargs) → any

Asynchronously render the template

classmethod

from_env(template, env, from_file=None, filter_with_colon=None, filters_as_globals=None, mode=None)Liquid

Initiate a template from a jinja environment

You should not specify any liquid-related extensions here. They will be added automatically.

No search path is allow to be passed here. Instead, use jinja2's loaders or use the constructor to initialize a template.

@Args: template: The template string or path of the template file env: The jinja environment from_file: Whether template is a file path. If True, a FileSystemLoader will be used in the env. filter_with_colon: Whether enable to use colon to separate filter and its arguments (i.e. {{a | filter: arg}}). If False, will fallback to use parentheses ({{a | filter(arg)}}) filters_as_globals: Whether also use filters as globals Only works in wild mode mode: The mode of the engine. - standard: Most compatibility with the standard liquid engine - wild: The liquid- and jinja-compatible mode - jekyll: The jekyll-compatible mode

@Returns: A Liquid object