adammark / Markup.js

Powerful JavaScript templates
317 stars 51 forks source link

The replacement symbol of template engine {{ and }} conflicts with the template engine of other frameworks. What can you do about it? #65

Open return-com opened 5 years ago

return-com commented 5 years ago

The replacement symbol of template engine {{ and }} conflicts with the template engine of other frameworks. What can you do about it?

Hellal1997 commented 2 months ago

Handlebar.js

Handlebars.registerHelper('customHelper', function(options) { // your custom logic here });

var template = Handlebars.compile("Hello, {{name}}!"); // Default // Change delimiters Handlebars.templates['my-template'] = Handlebars.compile("Hello, [[name]]!", { delimeters: ['[[', ']]'] });

  1. Mustache

var Mustache = require('mustache');

var template = "Hello, {{{name}}}!"; var output = Mustache.render(template, { name: "World" });

// Mustache does not support custom delimiters directly. You need to preprocess the template text.

  1. EJS

const ejs = require('ejs');

const template = "

Hello, <%= name %>!

"; // Default const options = { delimiter: '?' }; // Custom delimiter const output = ejs.render(template, { name: 'World' }, options);

  1. Jinja2

from jinja2 import Environment, FileSystemLoader

env = Environment( loader=FileSystemLoader('templates'), block_start_string='[%', block_end_string='%]', variable_start_string='[[', variable_end_string=']]' )

template = env.get_template('template.html') output = template.render(name="World")

  1. Twig (PHP)$loader = new \Twig\Loader\FilesystemLoader('/path/to/templates'); $twig = new \Twig\Environment($loader, [ 'debug' => true, 'autoescape' => false, 'charset' => 'utf-8', 'strict_variables' => false, 'cache' => '/path/to/compilation_cache', 'auto_reload' => true, 'optimizations' => -1, ]);

$twig->setDelimiters(array( 'tag_comment' => array('{#', '#}'), 'tag_block' => array('{%', '%}'), 'tag_variable' => array('{{', '}}'), ));

  1. Liquid

Liquid::Template.register_filter(MyCustomFilter)