I solved this by adding the current tenant to the liquid variables in my liquidize method like so:
Liquid::Template.parse(layout_code).render(model_content.merge('template_content' => templ, 'settings' => current_tenant, 'theme_id' => current_tenant.theme.id), :filters => [LiquidFilters])
The important part is:
'settings' => current_tenant, 'theme_id' => current_tenant.theme.id
These two adds a liquid variable named settings and theme_id which contains the theme id and the current_tenant.
These varaibles can be accessed normally within the template files (liquid files) or through context["theme_id"]
when inside a liquid tag definition.
Full example:
class SnippetFile < Liquid::Tag
class SnippetFile < Liquid::Tag
# Include the stylesheet tag link helper
include ActionView::Helpers::AssetTagHelper
def initialize(tag_name, variables, tokens)
@variables = variables.split(" ")
@default_name = @variables[0]
@file_name = @variables[1]
super
end
def render(context)
if @file_name.present? && (context[@file_name.strip]).present?
content = CodeFile.find_by(hierarchy: 'snippet', name: context[@file_name.strip], theme_id: context["theme_id"])
else
content = CodeFile.find_by(hierarchy: 'snippet', name: @default_name, theme_id: context["theme_id"])
end
Liquid::Template.parse(content.code).render(context)
end
end
Liquid::Template.register_tag('snippet_file', SnippetFile)