CustomTagParser mixin
Mixin for custom tag parsers.
Implement this mixin to create custom tags with custom parsing logic.
Basic Usage
class MyTag extends AbstractTag with CustomTagParser {
MyTag(super.content, super.filters);
@override
Parser parser([LiquidConfig? config]) {
return someTag('mytag', config: config);
}
}
Custom Delimiters
When parser is called with a LiquidConfig, use the factory functions with that config to support custom delimiters:
@override
Parser parser([LiquidConfig? config]) {
return (createTagStart(config) &
string('mytag').trim() &
createTagEnd(config))
.map((_) => Tag('mytag', []));
}
Accessing Config During Evaluation
If your tag needs to re-parse content (e.g., a block tag with nested Liquid syntax), access the config from the evaluator's context:
@override
dynamic evaluate(Evaluator evaluator, Buffer buffer) {
final content = body[0].toString();
// Get the config to use the same delimiters as the parent template
final config = evaluator.context.config;
final liquid = Liquid(config: config ?? LiquidConfig.standard);
// Re-parse and render with the correct delimiters
final result = liquid.renderString(content, evaluator.context.all());
buffer.write(result);
}
Variable-Style Tags
For tags that use {{ }} syntax (like {{ super() }}), override
delimiterType to return TagDelimiterType.variable:
@override
TagDelimiterType get delimiterType => TagDelimiterType.variable;
@override
Parser parser([LiquidConfig? config]) {
return (createVarStart(config) &
string('super').trim() &
char('(').trim() &
char(')').trim() &
createVarEnd(config))
.map((_) => Tag('super', []));
}
Properties
- delimiterType → TagDelimiterType
-
The delimiter type this tag uses.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
parser(
[LiquidConfig? config]) → Parser - Returns the parser for this custom tag.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited