Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
39
rated 0 times [  41] [ 2]  / answers: 1 / hits: 45635  / 12 Years ago, wed, december 19, 2012, 12:00:00

I'm trying to template a template, like below:



{{{
{
name : {{name}},
description : {{description}}
}
}}}

{{{debug this}}}




<h1>{{name}}</h1>




Where I want to triple brackets to stay, but double brackets to be replaced with the JSON passed in. Anyone know the best way to do this without writing post-process JS code, and if not, is there a good nodeJS template engine for this type of scenario?


More From » node.js

 Answers
20

You can switch delimiters to something that won't conflict with the triple mustaches, like erb-style tags:



{{=<% %>=}}
{{{
{
name: <% name %>,
description: <% description %>
}
}}}
{{{debug this}}}
<%={{ }}=%>


Note that you can do this as many times as you like throughout your template. Any time you run into something that conflicts, pick a new set of delimiters :)


[#81344] Monday, December 17, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
terrence

Total Points: 120
Total Questions: 115
Total Answers: 87

Location: England
Member since Fri, May 22, 2020
4 Years ago
terrence questions
Sat, Jun 5, 21, 00:00, 3 Years ago
Wed, Jun 17, 20, 00:00, 4 Years ago
;