liquid
liquid copied to clipboard
Am I doing this right?
Is the code snippet below following best practices?
Should I be doing this on each page view?
The problem is that the variable theme can change on a per request basis so I have to set the file_system everytime. Is this ok or will it impact performance in a big way?
Liquid::Template.file_system = Liquid::LocalFileSystem.new("/path/to/liquid/#{theme.id/")
index_template = File.read("....")
template = Liquid::Template.parse(index_template)
result = template.render(h)
render html: result.html_safe
Any comments?
Appreciate it!
There shouldn't be any problems with that approach. You'll likely want to do some template caching if you're very worried about performance (Liquid does not cache internally, though you can rely on the kernel to do some caching).