私はMustacheを初めて使用し、すでにそれを使用しているWebサイトで作業しています。このサイトのフォルダにMustacheテンプレートのセットがあります。これらは、次のようにメインhtmlのSekizaiタグで呼び出されます。
<html>
<head>...</head>
...
<body>
{% block body_content %}{% endblock %}
{% mustachejs "dashboard_module" %}
{% mustachejs "dashboard_add_module" %}
{% mustachejs "dashboard_empty_module" %}
{% mustachejs "login_popup" %}
{% mustachejs "add_account_types_popup" %}
{% mustachejs "add_account_manual_popup" %}
{% mustachejs "add_account_success_popup" %}
{% mustachejs "chart_linearprogress" %}
{% mustachejs "adviser_popover" %}
{% mustachejs "add_event_popup" %}
</body>
</html>
これにより、次のようなスクリプトタグが生成されます。
<script>Mustache.TEMPLATES=Mustache.TEMPLATES||
{};Mustache.TEMPLATES['add_event_popup']='<div id="AddAccountsPopup" class="add-event-popup">\n
<div class="addAccountsContainer">\n ... </script>
次に、別のjsファイルで、クリックイベントに次のようなテンプレートの1つを表示します。
function my func(){
var evnt_btn = $('.add-evnt-btn');
var template;
// get mustache template
template = $( Mustache.render( 'add_event_popup' ));
evnt_btn.click(function(){
template.show();
});
}
もちろん、myfunc()の内容は機能しません。どうやってやるの?