Place the JavaScript code in a separate JavaScript file. Use `Reference to the template
Use template tags
<script>
<#escape x as x?html>
// The ${ symbols in this context will be interpreted by JavaScript.
var template = `User: ${userName}, Time: ${new Date()}`;
</#escape>
</script>
Modify the freemarker configuration in FreeMarkerConfig.java.
freemarker.template.Configuration cfg = new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_34);
// Add interpolation syntax configuration
cfg.setInterpolationSyntax(Configuration.SQUARE_BRACKET_INTERPOLATION_SYNTAX);
The template is being used right now.[=xxx] To obtain interpolation values
<!-- Before modification -->
${Content.title}
<!-- After modification -->
[=Content.title]