Sha256: 0b185eb3e951df26b919b581152bda5ce7bb380c85d6c2255b08fe01c215324a

Contents?: true

Size: 1.53 KB

Versions: 5

Compression:

Stored size: 1.53 KB

Contents

# Liquid

Scribo uses liquid for all its template rendering, liquid is simple and safe.
You can read more about liquid here: https://shopify.github.io/liquid/

When you render a template, you can pass it assigns and registers.
The difference is subtle: assigns are exposed to the template, while registers are exposed to Drops, Tags, and Filters.

## Customizing

### Filters
Filters are methods which take one or more parameters and return a value.
Filters can access the context and registers as in the below example: 

```ruby
module RenderFilter
  def render(input)
    template = Liquid::Template.parse(input)
    template.render(@context, registers: @context.registers)
  end
end

Liquid::Template.register_filter(RenderFilter)
```

### Tags

"Tags" are tags that take any number of arguments, but do not contain a block of template code.

```ruby
# Renders content
#
# {% render variable%}
class RenderTag < Liquid::Tag
  def initialize(tag_name, markup, options)
    super
    @name = markup.strip
  end

  def render(context)
    value = Liquid::VariableLookup.parse(@name).evaluate(context)
    template = Liquid::Template.parse(value)
    template.render(context, registers: context.registers)
  end
end

Liquid::Template.register_tag('render', RenderTag)
```

### Block tags

"Blocks" are tags that contain a block of template code which is delimited by a {% end<TAGNAME> %} tag.

## Reference

https://github.com/Shopify/liquid/wiki/Liquid-for-Programmers
https://github.com/Shopify/liquid/wiki/Liquid-for-Designers
https://shopify.github.io/liquid/

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
scribo-1.0.44 docs/liquid.md
scribo-1.0.43 docs/liquid.md
scribo-1.0.42 docs/liquid.md
scribo-1.0.41 docs/liquid.md
scribo-1.0.40 docs/liquid.md