My Cart

Close

tag block sample

class Random < Liquid::Block def initialize(markup, tokens) super @rand = markup.to_i end

def render(context) if rand(@rand) == 0 super else ’’ end end end

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?