require 'json'
module Jekyll
class ImageTag < Liquid::Tag
def initialize(tag_name, name, tokens)
super
@name = name
@file = File.read('manifest.json')
@data_hash = JSON.parse(@file)
puts @data_hash // => { "0.js"=>"js/0.js" }
end
def render(context)
a = "0.js"
puts a // => 0.js
puts @name // => 0.js
puts a.class // => String
puts @name.class // => Liquid::Token
puts @data_hash[@name] // => Empty string ??!? But it should be js/0.js
puts @data_hash[a] // => js/0.js
end
end
end
Liquid::Template.register_tag('image', Jekyll::ImageTag)
In my .html file:
<img src="{% image 0.js %}" alt="">
Should I convert the name
argument into String? How should I do this?
Thank you