I’m new to Mustache and I’m working on a website already using it. I have a set of Mustache templates in a folder in this site. They are called with Sekizai tags in the main html like this:
<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>
this produces script tags like:
<script>Mustache.TEMPLATES=Mustache.TEMPLATES||
{};Mustache.TEMPLATES['add_event_popup']='<div id="AddAccountsPopup" class="add-event-popup">\n
<div class="addAccountsContainer">\n ... </script>
Now in another js file I want to show on a click event one of these templates, like:
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();
});
}
What’s in myfunc() doesn’t work of course! How can I do that?
Found it: