liquid icon indicating copy to clipboard operation
liquid copied to clipboard

Am I doing this right?

Open gitleet opened this issue 9 years ago • 2 comments

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

gitleet avatar Apr 23 '17 17:04 gitleet

Any comments?

Appreciate it!

gitleet avatar May 07 '17 18:05 gitleet

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).

pushrax avatar Jun 02 '17 20:06 pushrax