View Source Solid.Tag behaviour (solid v0.17.1)

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 tag
  • render 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/

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

Callbacks

Link to this callback

render(list, t, keyword)

View Source

Define how to render your tag. Third argument are the options passed to Solid.render/3

@callback spec(module()) :: NimbleParsec.t()

Build and return NimbleParsec expression to parse your tag. There are some helper expressions that can be used:

Functions

@spec basic(String.t()) :: NimbleParsec.t()

Basic custom tag spec that accepts optional arguments

Link to this function

eval(tag, context, options)

View Source
@spec eval(any(), Solid.Context.t(), keyword()) :: {iolist() | nil, Solid.Context.t()}

Evaluate a tag and return the condition that succeeded or nil