mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Added a bit of text description to the multiply example (where we use an assignment in the custom tag code)
@@ -108,12 +108,14 @@ Liquid::Template.register_tag('random', Random)
|
|||||||
```
|
```
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
@template = Liquid::Template.parse(" {% random 5 %}")
|
@template = Liquid::Template.parse("{% random 5 %}")
|
||||||
@template.render # => "3"
|
@template.render # => "3"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Using Assignments in Templates
|
### Using Assignments in Templates
|
||||||
|
|
||||||
|
You can also use assigned variables in your tags. To do so, use the context object passed to your render() method. In this example, we multiply any value supplied to the parameter as a tag by the configured "multiply_by" assigned value.
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class Multiply < Liquid::Tag
|
class Multiply < Liquid::Tag
|
||||||
def initialize(tag_name, factor, tokens)
|
def initialize(tag_name, factor, tokens)
|
||||||
|
|||||||
Reference in New Issue
Block a user