LiquidConfig class
Configuration for Liquid template parsing.
This class holds delimiter configuration and other parser options. Create instances to customize how templates are parsed.
Basic Usage
// Custom delimiters
final config = LiquidConfig(
tagStart: '[%',
tagEnd: '%]',
varStart: '[[',
varEnd: ']]',
);
final liquid = Liquid(config: config);
final template = liquid.parse('[% if user %]Hello [[name]]![% endif %]');
print(template.render({'user': true, 'name': 'Alice'})); // Hello Alice!
Presets
Two presets are available for common use cases:
// Standard Liquid delimiters (default)
final standard = LiquidConfig.standard;
// Uses: {% %} for tags, {{ }} for variables
// ERB-style delimiters
final erb = LiquidConfig.erb;
// Uses: <% %> for tags, <%= %> for variables
Whitespace Control
The stripMarker (default: -) enables whitespace stripping when placed
inside delimiters:
final liquid = Liquid();
final template = liquid.parse('''
{%- if true -%}
Hello
{%- endif -%}
''');
print(template.render()); // 'Hello' (whitespace stripped)
Building Custom Tags
When building custom tags, use the factory functions with your config:
final config = LiquidConfig(tagStart: '[%', tagEnd: '%]');
// Create a custom tag parser
Parser myTagParser() {
return someTag('mytag', config: config);
}
See also:
- Liquid for parsing templates with custom delimiters
- LiquidTemplate for rendering parsed templates
- createTagStart, createTagEnd, createVarStart, createVarEnd for building custom parsers
Constructors
- LiquidConfig({String tagStart = '{%', String tagEnd = '%}', String varStart = '{{', String varEnd = '}}', String stripMarker = '-'})
-
Creates a new LiquidConfig with the specified delimiters.
const
Properties
- delimiterStartChars → String
-
Returns the first character(s) that could start a delimiter.
no setter
- hashCode → int
-
The hash code for this object.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stripMarker → String
-
The marker used for whitespace stripping. Default:
-final - tagEnd → String
-
The closing delimiter for tags. Default:
%}final - tagEndStrip → String
-
Tag end with whitespace stripping (e.g.,
-%})no setter - tagStart → String
-
The opening delimiter for tags. Default:
{%final - tagStartStrip → String
-
Tag start with whitespace stripping (e.g.,
{%-)no setter - varEnd → String
-
The closing delimiter for variable output. Default:
}}final - varEndStrip → String
-
Variable end with whitespace stripping (e.g.,
-}})no setter - varStart → String
-
The opening delimiter for variable output. Default:
{{final - varStartStrip → String
-
Variable start with whitespace stripping (e.g.,
{{-)no setter
Methods
-
copyWith(
{String? tagStart, String? tagEnd, String? varStart, String? varEnd, String? stripMarker}) → LiquidConfig - Creates a copy of this config with the specified fields replaced.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
Constants
- erb → const LiquidConfig
- ERB-style delimiters.
- standard → const LiquidConfig
- Standard Liquid delimiters (default).