diff --git a/Liquid-for-Programmers.textile b/Liquid-for-Programmers.textile index 18b613a..6358376 100644 --- a/Liquid-for-Programmers.textile +++ b/Liquid-for-Programmers.textile @@ -52,6 +52,30 @@ Once the filter is globally registered you can simply use it: @template.render # => "hi" +h3. Create your own tags + +To create a new tag, simply inherit from Liquid::Tag and register your block with Liquid::Template + +
+ 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)
+
+
+
+@template = Liquid::Template.parse(" {% random 5 %}")
+@template.render # => "3"
+
+
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)
@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?
-
+
\ No newline at end of file