I’ve created a custom Liquid tag. I want this tag to create (or append) an array called facilities. My code is copied below. It seems to do this just fine as evidenced by the print statement. However, when I try to access the data in a page or post with {{ page.facilities }} I get a null value returned. It seems the facilities array isn’t kept.
How can I keep my facilities array?
module Jekyll
class Facility < Liquid::Tag
def initialize(tag_name, input, tokens)
super
@name = input.strip
end
def render(context)
begin
page = context.environments.first['page']
@tags = page['tags']
@tags.append(@name) unless @tags.include?(@name)
page['facilities'] = [] unless page.key?('facilities')
@facilities = page['facilities']
print( "Facilities: #{@facilities}")
@facilities << @name unless @facilities.include?(@name)
end
end
end
Liquid::Template.register_tag('facility', Jekyll::Facility)