Solid.Tag behaviour (solid v0.15.2) View Source
This module define behaviour for tags.
To implement new tag you need to create new module that implement the Tag
behaviour:
defmodule MyCustomTag do
import NimbleParsec
@behaviour Solid.Tag
@impl true
def spec(_parser) do
space = Solid.Parser.Literal.whitespace(min: 0)
ignore(string("{%"))
|> ignore(space)
|> ignore(string("my_tag"))
|> ignore(space)
|> ignore(string("%}"))
end
@impl true
def render(_tag, _context, _options) do
[text: "my first tag"]
end
end
spec
define how to parse your tagrender
define how to render your tag
Then add the tag to your parser
defmodule MyParser do
use Solid.Parser.Base, custom_tags: [MyCustomTag]
end
Then pass the custom parser as option
"{% my_tag %}"
|> Solid.parse!(parser: MyParser)
|> Solid.render()
Control flow tags can change the information Liquid shows using programming logic.
More info: https://shopify.github.io/liquid/tags/control-flow/
Link to this section Summary
Callbacks
Define how to render your tag.
Third argument are the options passed to Solid.render/3
Build and return NimbleParsec
expression to parse your tag. There are some helper expressions that can be used
Functions
Basic custom tag spec that accepts optional arguments
Evaluate a tag and return the condition that succeeded or nil
Link to this section Callbacks
Specs
render(list(), Solid.Context.t(), keyword()) :: {[Solid.Template.rendered_data()], Solid.Context.t()} | String.t()
Define how to render your tag.
Third argument are the options passed to Solid.render/3
Specs
spec(module()) :: NimbleParsec.t()
Build and return NimbleParsec
expression to parse your tag. There are some helper expressions that can be used:
Link to this section Functions
Specs
basic(String.t()) :: NimbleParsec.t()
Basic custom tag spec that accepts optional arguments
Specs
eval(any(), Solid.Context.t(), keyword()) :: {iolist() | nil, Solid.Context.t()}
Evaluate a tag and return the condition that succeeded or nil