How to output ${expression} in Freemarker without it being interpreted?

后端 未结 8 1124
隐瞒了意图╮
隐瞒了意图╮ 2020-12-05 06:39

I\'m trying to use Freemarker in conjunction with jQuery Templates.

Both frameworks use dollar sign/curly brackets to identify expressions for substitution (or as th

相关标签:
8条回答
  • 2020-12-05 07:34

    For longer sections without FreeMarker markup, use <#noparse>...</#noparse>.

    Starting with FreeMarker 2.3.28, configure FreeMarker to use square bracket syntax ([=exp]) instead of brace syntax (${exp}) by setting the interpolation_syntax configuration option to square_bracket.

    Note that unlike the tag syntax, the interpolation syntax cannot be specified inside the template. Changing the interpolation syntax requires calling the Java API:

    Configuration cfg;
    // ...
    cfg.setInterpolationSyntax(SQUARE_BRACKET_INTERPOLATION_SYNTAX);
    

    Then FreeMarker will consider ${exp} to be static text.

    Do not confuse interpolation syntax with tag syntax, which also can have square_bracket value, but is independent of the interpolation syntax.

    When using FreeMarker-based file PreProcessor (FMPP), either configure the setting via config.fmpp or on the command-line, such as:

    fmpp --verbose --interpolation-syntax squareBracket ...
    

    This will call the appropriate Java API prior to processing the file.

    See also:

    • https://freemarker.apache.org/docs/dgui_misc_alternativesyntax.html
    • http://fmpp.sourceforge.net/settings.html#templateSyntax
    0 讨论(0)
  • 2020-12-05 07:37

    Another option is to use #include with parse=false option. That is, put your jQuery Templates into the separate include page and use parse=false so that freemarker doesn't try and parse it.

    This would be a good option when the templates are larger and contain double quotes.

    0 讨论(0)
提交回复
热议问题