The render
method of Liquid::Block
returns the text between the begin and end tags. So just change your render method to this:
def render(context)
p super
end
質問
I am trying to build custom block using the Liquid Templating. Following is my code:
module MyModule
module Blocks
class MyBlock < Liquid::Block
def initialize(tag, markup, tokens)
super
@tag = tag
@tokens = tokens
@markup = markup
end
def render(context)
p @tokens
end
end
end
end
Liquid::Template.register_tag('myblock', MyModule::Blocks::MyBlock)
And in my template, I have the following code:
{% for i in mypages %}
{% myblock %} {{ i.title }} {% endmyblock %}
{% endfor %}
My question is how do I get all the content that is passed between the myblock
tags. i.e., how do I make i.title
available to myblock
's render
function. I thought tokens
captures this, but when I puts tokens
it outputs []
Thank You
解決
The render
method of Liquid::Block
returns the text between the begin and end tags. So just change your render method to this:
def render(context)
p super
end