Can the Liquid Ruby template engine deal with Rails forms?

社会主义新天地 提交于 2019-12-05 19:57:29

You can register your own tag blocks with Liquid, but it doesn't came out of the box.

If you check the documentation, you will notice that you can create your own tag blocks.

You can register your own tag block

class LiquidForm < Liquid::Block
  def initialize(tag_name, markup, tokens)
     super
  end

  def render(context)
    form_tag("/hello_word") do 
      input_tag "hello"
    end
  end
end

Liquid::Template.register_tag('liquid_form', LiquidForm)

And then parse the text you want with liquid

text = " {% liquid_form %} Form content {% endliquid_form %} "
@template = Liquid::Template.parse(text)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!