2

I have trouble understanding why my below code fails partially. I try to create Liquid tag for Jekyll. While the the class member "text" is set, the member "xyz" is not set at all. But why?

module MyModule
  class MyTag < Liquid::Tag
    def initialize(tag_name, text, tokens)
      super
      @text = text
      @xyz = "HELLO"
    end

    def render(context)
      "Output  #{@text} #{@xyz}"
    end
  end
end

Liquid::Template.register_tag('my_tag', MyModule::MyTag)

With calling the following

{% my_tag de 1234 %}

The output of the above is:

Output de 1234

I expected there would be "HELLO" as well, like:

Output de 1234 HELLO

What do I miss?

The original code from the Liquid class is here.

Christian
  • 7,062
  • 5
  • 36
  • 39

1 Answers1

2

Your code seems to work fine with Ruby 2.1.5 and liquid-3.0.6 :

require 'liquid'
module MyModule
  class MyTag < Liquid::Tag
    def initialize(tag_name, text, tokens)
      super
      @text = text
      @xyz = "HELLO"
    end

    def render(context)
      "Output  #{@text} #{@xyz}"
    end
  end
end

Liquid::Template.register_tag('my_tag', MyModule::MyTag)

@template = Liquid::Template.parse("{% my_tag de 1234 %}")
puts @template.render
#=> "Output  de 1234  HELLO"
Eric Duminil
  • 52,989
  • 9
  • 71
  • 124
  • I can confirm I have the same output running it from the CLI. It's still broken when using it combined with Jekyll. – Christian Nov 16 '16 at 10:38