FrancisTemplate.Liquid (Francis Template v0.2.0)

View Source

Liquid template engine backed by Solid.

Add Solid alongside francis_template in the host application because it is an optional dependency:

def deps do
  [
    {:francis_template, "~> 0.2"},
    {:solid, "~> 1.0"}
  ]
end

.liquid files are registered automatically. Atom keys in assigns are recursively converted to strings, so ordinary Elixir maps work naturally:

# priv/templates/product.liquid
# <h1>{{ product.title | escape }}</h1>

render(conn, "product.liquid", product: %{title: "A great mug"})

Solid's standard tags and filters are available. The render tag also works without extra configuration: partials are resolved from the configured FrancisTemplate root using Liquid's _name.liquid convention.

{% render "product_card", product: product %}
# resolves priv/templates/_product_card.liquid

Configuration

Parse and render options are passed through to Solid:

config :francis_template,
  liquid: [
    parse_options: [tags: MyApp.LiquidTags.all()],
    render_options: [
      custom_filters: MyApp.LiquidFilters,
      strict_variables: true,
      strict_filters: true
    ]
  ]

:parse_options are passed to Solid.parse!/2. :render_options are passed to Solid.render!/3 and can include :custom_filters, :strict_variables, :strict_filters, :matcher_module, :file_system, and :cache_module. A custom :file_system overrides the default partial lookup.

This engine implements the open Liquid language supported by Solid. Shopify's hosted theme runtime adds store-specific objects, tags, and filters; provide those as assigns and Solid custom tags/filters when an application needs them.