How to change the default delimiter of mustache.js?

by elise_daugherty , in category: Javascript , 7 months ago

How to change the default delimiter of mustache.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lily , 7 months ago

@elise_daugherty 

If you want to change the default delimiter of mustache.js, you can use the Mustache.tags object to set new tag delimiters. Here's how you can do it:

  1. Set the new tag delimiters:
1
Mustache.tags = ['[[', ']]'];


  1. Use the new delimiters in your template:
1
2
3
<script id="template" type="x-tmpl-mustache">
    Hello, [[name]]!
</script>


  1. Render the template with the new delimiters:
1
2
3
4
var template = document.getElementById('template').innerHTML;
var data = { name: 'John' };
var rendered = Mustache.render(template, data);
console.log(rendered); // Output: Hello, John!


By following these steps, you can change the default delimiter of mustache.js to your preferred characters.

Related Threads:

How to change the default theme of phpMyAdmin?
How to change default colors in vuetify?
How to change the default text in dropzone.js?
How to change default database in codeigniter?
How to change default language in laravel?
How to change default hash password in cakephp?