v10.20.0
-Sync and AsyncThere are synchronous and asynchronous versions of each of the methods demonstrated on this page. See the Liquid API for a complete reference.
+Experimental+ +Note that this is an experimental feature and future APIs are subject to change. And internal structures returned can be changed w/o a major version bump.
+Sync and AsyncThere are synchronous and asynchronous versions of each of the methods demonstrated on this page. See the [Liquid API][liquid-api] for a complete reference.
Variables
Retrieve the names of variables used in a template with
@@ -102,7 +105,7 @@ const engine = new Liquid() -const template = engine.parse(`\ +const template = engine.parse(` <p> {% assign title = user.title | capitalize %} {{ title }} {{ user.first_name | default: user.name }} {{ user.last_name }} @@ -185,7 +188,7 @@ engine.globaLiquid.variables(template). It returns an array of strings, one string for each distinct variable, without its properties.Partial Templates
By default, LiquidJS will try to load and analyze any included and rendered templates too.
import { Liquid } from 'liquidjs' -const footer = `\ +const footer = ` <footer> <p>© {{ "now" | date: "%Y" }} {{ site_name }}</p> <p>{{ site_description }}</p> @@ -193,7 +196,7 @@ engine.globa const engine = new Liquid({ templates: { footer } }) -const template = engine.parse(`\ +const template = engine.parse(` <body> <h1>Hi, {{ you | default: 'World' }}!</h1> {% assign some = 'thing' %} @@ -214,7 +217,7 @@ engine.globa[ 'you' ]If an
-{% include %}tag uses a dynamic template name (one that can’t be determined without rendering the template) it will be ignored, even ifpartialsis set totrue.Advanced Usage
The examples so far all use convenience methods of the
+Liquidclass, intended to cover the most common use cases. Instead, you can work with analysis results directly, which expose the row, column and file name for every occurrence of each variable.Advanced Usage
The examples so far all use convenience methods of the
Liquidclass, intended to cover the most common use cases. Instead, you can work with analysis results directly, which expose the row, column and file name for every occurrence of each variable.This is an example of an object returned from
Liquid.analyze(), passing it the template from the Partial Template section above.{ variables: { @@ -271,7 +274,7 @@ engine.globaNot all methods are required, depending in the kind of tag. If it’s a block with a start tag, end tag and any amount of Liquid markup in between, it will need to implement the
children()method.children()is defined as a generator, so that we can use it in synchronous and asynchronous contexts, just likerender(). It should return HTML content, output statements and tags that are child nodes of the current tag.The
blockScope()method is responsible for telling LiquidJS which names will be in scope for the duration of the tag’s block. Some of these names could depend on the tag’s arguments, and some will be fixed, likeforloopfrom the{% for %}tag.Whether a tag is an inline tag or a block tag, if it accepts arguments it should implement
-arguments(), which is responsible for returning the tag’s arguments as a sequence ofValueinstances or tokens of typeValueToken.This example demonstrates these methods for a block tag. See LiquidJS’s built-in tags for more examples.
+This example demonstrates these methods for a block tag. See LiquidJS’s built-in tags for more examples.
import { Liquid, Tag, Hash } from 'liquidjs' class ExampleTag extends Tag { @@ -314,7 +317,7 @@ engine.globa