mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-02 16:45:12 -07:00
Clarify usage of super in Block.render
@@ -101,11 +101,8 @@ class Random < Liquid::Block
|
|||||||
end
|
end
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
if rand(@rand) == 0
|
value = rand(@rand)
|
||||||
super
|
super.sub('^^^', value.to_s) # calling `super` returns the content of the block
|
||||||
else
|
|
||||||
''
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -113,7 +110,7 @@ Liquid::Template.register_tag('random', Random)
|
|||||||
```
|
```
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
text = " {% random 5 %} wanna hear a joke? {% endrandom %} "
|
text = " {% random 5 %} you have drawn number ^^^, lucky you! {% endrandom %} "
|
||||||
@template = Liquid::Template.parse(text)
|
@template = Liquid::Template.parse(text)
|
||||||
@template.render # => In 20% of the cases, this will output "wanna hear a joke?"
|
@template.render # will return "you have drawn number 1, lucky you!" in 20% of cases
|
||||||
```
|
```
|
||||||
Reference in New Issue
Block a user