freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Dekany (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (FREEMARKER-106) Unable to parse variable containing special char ${# with freemarker.template.Template.process(object,writer)
Date Thu, 01 Nov 2018 12:55:00 GMT

    [ https://issues.apache.org/jira/browse/FREEMARKER-106?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16671573#comment-16671573
] 

Daniel Dekany edited comment on FREEMARKER-106 at 11/1/18 12:54 PM:
--------------------------------------------------------------------

Then {{$\{#array[@]}}} is not meant to be a FreeMarker interpolation at all, but static text.
So, there's a clash between the Bash syntax and the FreeMarker syntax, and traditionally
you had to use {{<#noparse>...</#noparse>}} and similar verbose workarounds. But
since 2.3.28 there's an {{interpolationSyntax}} or {{interpolation_syntax}} configuration
setting, and you should chose square bracket interpolation syntax with that. Then {{$\{...}}}
is just static text, and {{[=...]}} is used for FreeMarker interpolations. (I would also use
square bracket tag syntax together with that, but that's just aesthetics.) See also: [https://freemarker.apache.org/docs/dgui_misc_alternativesyntax.html]


was (Author: ddekany):
Then {{$\{#array[@]}}} is not meant to be a FreeMarker interpolation at all, but static text.
So, there's an clash between the Bash syntax and the FreeMarker syntax, and traditionally
you had to use {{<#noparse>...</#noparse>}} and similar verbose workarounds. But
since 2.3.28 there's an {{interpolationSyntax}} or {{interpolation_syntax}} configuration
setting, and you should chose square bracket interpolation syntax with that. Then {{$\{...}}}
is just static text, and {{[=...]}} is used for FreeMarker interpolations. (I would also use
square bracket tag syntax together with that, but that's just aesthetics.) See also: [https://freemarker.apache.org/docs/dgui_misc_alternativesyntax.html]

> Unable to parse variable containing special char ${# with freemarker.template.Template.process(object,writer)
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: FREEMARKER-106
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-106
>             Project: Apache Freemarker
>          Issue Type: Bug
>          Components: engine
>    Affects Versions: 2.3.23
>            Reporter: Amar Gurung
>            Priority: Major
>
> Unable to parse variable containing $\{# e.g ${#marker_files[@]} or $\{#array[@]}
> Sample snippet:
> -----------------------------
> Configuration cfg = new Configuration(Configuration.VERSION_2_3_28);
>  cfg.setLogTemplateExceptions(false);
>  cfg.setClassForTemplateLoading(FtlExpressionEvaluator.class, "templates");
>  cfg.setDefaultEncoding("UTF-8");
>  cfg.setLocale(Locale.US);
>  cfg.setTemplateExceptionHandler(TemplateExceptionHandler.IGNORE_HANDLER);
>  cfg.setNumberFormat("0.######");
> Template t = new Template("freeMarkerTemplate", new StringReader(line), cfg);
>  
> Error stack:
> freemarker.core.ParseException: Syntax error in template "freeMarkerTemplate" in line
1, column 13:
> Lexical error: encountered "m" (109), after "#".
>  at freemarker.core.TokenMgrError.toParseException(TokenMgrError.java:260)
>  at freemarker.template.Template.<init>(Template.java:269)
>  at freemarker.template.Template.<init>(Template.java:203)
>  at freemarker.template.Template.<init>(Template.java:182)
>  at freemarker.template.Template.<init>(Template.java:125)
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message