Last active
April 16, 2021 20:14
-
-
Save niccai/8859372 to your computer and use it in GitHub Desktop.
Changing lodash/underscore template settings in Node.js to use Mustache style braces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Client side, you typically see the template style changed to {{ }} like so... | |
_.templateSettings = { | |
interpolate : /\{\{(.+?)\}\}/gim, | |
evaluate: /\{\#(.+?)\#\}/gim | |
}; | |
/* | |
However, in Node.js, this causes issues when trying to render a template. | |
Likely, you haven't paid too much attention to the fact that you are setting | |
_.templateSettings outright above. Thus, losing other settings like escape and variable. | |
AND FOR NODE.JS, IMPORTS IS ALSO LOST. | |
*/ | |
// Therefore, you should set only what you need to explicitly. | |
_.templateSettings.interpolate = /\{\{(.+?)\}\}/gim; | |
_.templateSettings.evaluate = /\{\#(.+?)\#\}/gim; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment