I’m using Mustache in Rails 3 with this gem and I’m hitting a roadblock when trying to use Mustache in an instance where I would normally use yield :parameter.
<html>
<head>
<title><%= yield :page_title %></title>
</head>
</html>
Show post view:
<% content_for :page_title do %>
<%= SettingsList.site_title + " " + @post.title %>
<% end %>
Is there a way to reproduce this behavior with Mustache? It appears that there may be a way to work this out when the template is compiled:
mustache = MustacheClass.new
mustache[:yield_page_title] = content_for(:page_title)
But it seems that that would be awkward to work out with my current setup using the mustache_rails3 gem.
I’m also open to any answers that point out a good way to avoid this yield approach altogether. It would be possible to throw enough logic into a {{page_title}} tag to handle all my different cases of setting the title, but this seems far from ideal.
All of the logic for your Mustache templates should be put into the view file. For example, your
show.html.mustachetemplate should have an associated Ruby view file calledshow.rbwhere you can put any custom logic for the template.The template would use a
{{page_title}}callAnd the view file would define a
page_titlemethod to fill in the template