The comparison between liquid and mustche template engine.

As we know when we trying to render customer edited html template we'd better to use some other logic less or more safety template engine which won't provide too much unsafety functions to designer, like liquid or mustche --- 2 most popular template engines. Let's compare them on two aspects: 1. Integrate With Rails 2. Features for designers 1. Integrate With Rails Liquid: As long as you add this in configure file:
ActionView::Base::register_template_handler :liquid, LiquidView
Then you would be able to intead index.html.erb with index.html.liquid, any instance variable will be able to use in liquid template. Mustache: You need to install mustache rails plugin:
https://github.com/adamsalter/mustache-rails
here is a example: https://github.com/foca/mustache-on-rails-example What I most don't like mustache is it can't pass controller variable instance to mustache template. You need to create a file to provide data to mustache template, like:
class IndexView < MustacheRails # you have access to methods such as action_name controller_name and any url helpers # as action_view context is asked def questions context[:_questions].map(&:serializable_hash) end end
That means you need to creat not only a index.html.mustache but also index.rb file. That lame!!! 2. Features for designers Below are manuals for each template engine. Liquid: https://github.com/tobi/liquid/wiki/Liquid-for-Designers Mustache: http://mustache.github.com/mustache.5.html As we can see, Liquid support: Filter methods(Like string and number operation methods), Logic controlling tags (if-else, for loop, case..when block ....). But in mustache it only provide: fetch data from collection and section. (The behavior of the section is determined by the value of the key. False Values or Empty Lists) Conclusion: Mustache is weak on template helper methods, and awkward to integrate with rails. But I don't know what's the performance side of it.
blog comments powered by Disqus