Migrated from liquid-for-programmers v6

mojombo
2010-08-12 13:45:54 -07:00
parent b01222778d
commit 0fe3cc41a1
+25 -1
@@ -52,6 +52,30 @@ Once the filter is globally registered you can simply use it:
@template.render # => "<b>hi</b>"
</code></pre>
h3. Create your own tags
To create a new tag, simply inherit from Liquid::Tag and register your block with Liquid::Template
<pre><code>
class Random < Liquid::Tag
def initialize(tag_name, max, tokens)
super
@max = max.to_i
end
def render(context)
rand(@max).to_s
end
end
Liquid::Template.register_tag('random', Random)
</code></pre>
<pre><code>
@template = Liquid::Template.parse(" {% random 5 %}")
@template.render # => "3"
</code></pre>
h3. Create your own tag blocks
All tag blocks are parsed by liquid. To create a new block you just have to inherit from Liquid::Block and register your block with Liquid::Template
@@ -78,4 +102,4 @@ Liquid::Template.register_tag('random', Random)
<pre><code>
@template = Liquid::Template.parse(" {% random 5 %} wanna hear a joke? {% endrandom %} ")
@template.render # => in 20% of the cases this will output : wanna hear a joke?
</code></pre>
</code></pre>