You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by James Yong <ja...@apache.org> on 2020/12/12 09:43:04 UTC
Change ${...} to [=...] for freemarker template
Hi all,
Currently interpolation syntax used for freemarker template is ${...}.
This is the same as the interpolation syntax for template literal in javascript.
As a result, extra coding is needed to escape the interpolation expression for javascript coding with freemarker template.
Propose to change the use of ${...} to [=...] for freemarker template.
Reference:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
https://freemarker.apache.org/docs/dgui_misc_alternativesyntax.html#dgui_misc_alternativesyntax_interpolation
Regards,
James
Re: Change ${...} to [=...] for freemarker template
Posted by James Yong <ja...@apache.org>.
Created OFBIZ-12099 for this new feature.
On 2020/12/20 07:41:03, James Yong <ja...@apache.org> wrote:
> Hi all,
>
> Thanks for the feedbacks.
>
> Plan to allow freemarker square interpolation syntax, i.e. [=...],
> when the template filename extension is '.sqi.ftl'.
> So it will not affect existing templates that doesn't use js template literal.
> sqi is abbreviation for square interpolation.
>
> Regards,
> James
>
> On 2020/12/15 12:38:32, James Yong <ja...@apache.org> wrote:
> > Hi Michael,
> >
> > Please see my reply inline.
> >
> > Regards,
> > James
> >
> > On 2020/12/14 08:12:26, Michael Brohl <mi...@ecomify.de> wrote:
> > > Hi James,
> > >
> > > I cannot recall having any problems with that during the last 18 years
> > > of running OFBiz projects.
> > >
> > > Can you give us a real world example where this really is a problem?
> >
> > [James]
> > Some advantage of using template literal:
> >
> > 1. The following fragment will be highlighted or blocked by Content-Security-Policy due to the inline event handler. This is not a problem when the fragment is in template literal.
> > <button id="btn" onclick="doSomething()">
> >
> > 2. Form and its data can be separated / decoupled using template literal. This allows the form to be rendered only once at the server-side.
> >
> > 3. There is also tagged template literal. More about its possible use at https://2ality.com/2011/09/quasi-literals.html
> >
> > >
> > > Besides this, I am not in favour of a forced change in all of the
> > > codebase. Wouldn't it be possible to use both ways, leaving it up to the
> > > developer to use the [=...] Syntax where necessary?
> >
> > [James]
> > Let me check this possibility..
> >
> > >
> > > Best regards,
> > >
> > > Michael Brohl
> > >
> > > ecomify GmbH - www.ecomify.de
> > >
> > >
> > > Am 12.12.20 um 10:43 schrieb James Yong:
> > > > Hi all,
> > > >
> > > > Currently interpolation syntax used for freemarker template is ${...}.
> > > > This is the same as the interpolation syntax for template literal in javascript.
> > > > As a result, extra coding is needed to escape the interpolation expression for javascript coding with freemarker template.
> > > >
> > > > Propose to change the use of ${...} to [=...] for freemarker template.
> > > >
> > > > Reference:
> > > > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
> > > > https://freemarker.apache.org/docs/dgui_misc_alternativesyntax.html#dgui_misc_alternativesyntax_interpolation
> > > >
> > > > Regards,
> > > > James
> > >
> >
>
Re: Change ${...} to [=...] for freemarker template
Posted by James Yong <ja...@apache.org>.
Hi all,
Thanks for the feedbacks.
Plan to allow freemarker square interpolation syntax, i.e. [=...],
when the template filename extension is '.sqi.ftl'.
So it will not affect existing templates that doesn't use js template literal.
sqi is abbreviation for square interpolation.
Regards,
James
On 2020/12/15 12:38:32, James Yong <ja...@apache.org> wrote:
> Hi Michael,
>
> Please see my reply inline.
>
> Regards,
> James
>
> On 2020/12/14 08:12:26, Michael Brohl <mi...@ecomify.de> wrote:
> > Hi James,
> >
> > I cannot recall having any problems with that during the last 18 years
> > of running OFBiz projects.
> >
> > Can you give us a real world example where this really is a problem?
>
> [James]
> Some advantage of using template literal:
>
> 1. The following fragment will be highlighted or blocked by Content-Security-Policy due to the inline event handler. This is not a problem when the fragment is in template literal.
> <button id="btn" onclick="doSomething()">
>
> 2. Form and its data can be separated / decoupled using template literal. This allows the form to be rendered only once at the server-side.
>
> 3. There is also tagged template literal. More about its possible use at https://2ality.com/2011/09/quasi-literals.html
>
> >
> > Besides this, I am not in favour of a forced change in all of the
> > codebase. Wouldn't it be possible to use both ways, leaving it up to the
> > developer to use the [=...] Syntax where necessary?
>
> [James]
> Let me check this possibility..
>
> >
> > Best regards,
> >
> > Michael Brohl
> >
> > ecomify GmbH - www.ecomify.de
> >
> >
> > Am 12.12.20 um 10:43 schrieb James Yong:
> > > Hi all,
> > >
> > > Currently interpolation syntax used for freemarker template is ${...}.
> > > This is the same as the interpolation syntax for template literal in javascript.
> > > As a result, extra coding is needed to escape the interpolation expression for javascript coding with freemarker template.
> > >
> > > Propose to change the use of ${...} to [=...] for freemarker template.
> > >
> > > Reference:
> > > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
> > > https://freemarker.apache.org/docs/dgui_misc_alternativesyntax.html#dgui_misc_alternativesyntax_interpolation
> > >
> > > Regards,
> > > James
> >
>
Re: Change ${...} to [=...] for freemarker template
Posted by James Yong <ja...@apache.org>.
Hi Michael,
Please see my reply inline.
Regards,
James
On 2020/12/14 08:12:26, Michael Brohl <mi...@ecomify.de> wrote:
> Hi James,
>
> I cannot recall having any problems with that during the last 18 years
> of running OFBiz projects.
>
> Can you give us a real world example where this really is a problem?
[James]
Some advantage of using template literal:
1. The following fragment will be highlighted or blocked by Content-Security-Policy due to the inline event handler. This is not a problem when the fragment is in template literal.
<button id="btn" onclick="doSomething()">
2. Form and its data can be separated / decoupled using template literal. This allows the form to be rendered only once at the server-side.
3. There is also tagged template literal. More about its possible use at https://2ality.com/2011/09/quasi-literals.html
>
> Besides this, I am not in favour of a forced change in all of the
> codebase. Wouldn't it be possible to use both ways, leaving it up to the
> developer to use the [=...] Syntax where necessary?
[James]
Let me check this possibility..
>
> Best regards,
>
> Michael Brohl
>
> ecomify GmbH - www.ecomify.de
>
>
> Am 12.12.20 um 10:43 schrieb James Yong:
> > Hi all,
> >
> > Currently interpolation syntax used for freemarker template is ${...}.
> > This is the same as the interpolation syntax for template literal in javascript.
> > As a result, extra coding is needed to escape the interpolation expression for javascript coding with freemarker template.
> >
> > Propose to change the use of ${...} to [=...] for freemarker template.
> >
> > Reference:
> > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
> > https://freemarker.apache.org/docs/dgui_misc_alternativesyntax.html#dgui_misc_alternativesyntax_interpolation
> >
> > Regards,
> > James
>
Re: Change ${...} to [=...] for freemarker template
Posted by Michael Brohl <mi...@ecomify.de>.
Hi James,
I cannot recall having any problems with that during the last 18 years
of running OFBiz projects.
Can you give us a real world example where this really is a problem?
Besides this, I am not in favour of a forced change in all of the
codebase. Wouldn't it be possible to use both ways, leaving it up to the
developer to use the [=...] Syntax where necessary?
Best regards,
Michael Brohl
ecomify GmbH - www.ecomify.de
Am 12.12.20 um 10:43 schrieb James Yong:
> Hi all,
>
> Currently interpolation syntax used for freemarker template is ${...}.
> This is the same as the interpolation syntax for template literal in javascript.
> As a result, extra coding is needed to escape the interpolation expression for javascript coding with freemarker template.
>
> Propose to change the use of ${...} to [=...] for freemarker template.
>
> Reference:
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
> https://freemarker.apache.org/docs/dgui_misc_alternativesyntax.html#dgui_misc_alternativesyntax_interpolation
>
> Regards,
> James
Re: Change ${...} to [=...] for freemarker template
Posted by James Yong <ja...@apache.org>.
Hi Pawan,
Yes, all FTL code in framework and plugins will be changed.
Changes can be done using regular expression for the replacement.
So migration for custom or existing code should be relatively simple.
Regards,
James
On 2020/12/12 11:50:34, Pawan Verma <pa...@hotwaxsystems.com> wrote:
> Hi James,
>
> What is the scope of this effort? Are we talking about changing it to all
> the FTL code?
>
> AFAIK, When square bracket interpolation syntax is used, ${expression} and
> #{expression} in the template will be just static text, which is printed
> as-is. That means all the existing code will become stale, we need to
> change that also.
>
> And there will also be concern about migration from lower-release to
> higher-release.
>
> Please share your thoughts on this.
> --
> Thanks & Regards
> Pawan Verma
> Technical Consultant
> *HotWax Systems*
> *Enterprise open source experts*
> http://www.hotwaxsystems.com
>
>
> On Sat, Dec 12, 2020 at 3:59 PM Jacques Le Roux <
> jacques.le.roux@les7arts.com> wrote:
>
> > Hi James,
> >
> > I see no problems with that: +1
> >
> > Jacques
> >
> > Le 12/12/2020 à 10:43, James Yong a écrit :
> > > Hi all,
> > >
> > > Currently interpolation syntax used for freemarker template is ${...}.
> > > This is the same as the interpolation syntax for template literal in
> > javascript.
> > > As a result, extra coding is needed to escape the interpolation
> > expression for javascript coding with freemarker template.
> > >
> > > Propose to change the use of ${...} to [=...] for freemarker template.
> > >
> > > Reference:
> > >
> > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
> > >
> > https://freemarker.apache.org/docs/dgui_misc_alternativesyntax.html#dgui_misc_alternativesyntax_interpolation
> > >
> > > Regards,
> > > James
> >
> >
>
Re: Change ${...} to [=...] for freemarker template
Posted by Pawan Verma <pa...@hotwaxsystems.com>.
Hi James,
What is the scope of this effort? Are we talking about changing it to all
the FTL code?
AFAIK, When square bracket interpolation syntax is used, ${expression} and
#{expression} in the template will be just static text, which is printed
as-is. That means all the existing code will become stale, we need to
change that also.
And there will also be concern about migration from lower-release to
higher-release.
Please share your thoughts on this.
--
Thanks & Regards
Pawan Verma
Technical Consultant
*HotWax Systems*
*Enterprise open source experts*
http://www.hotwaxsystems.com
On Sat, Dec 12, 2020 at 3:59 PM Jacques Le Roux <
jacques.le.roux@les7arts.com> wrote:
> Hi James,
>
> I see no problems with that: +1
>
> Jacques
>
> Le 12/12/2020 à 10:43, James Yong a écrit :
> > Hi all,
> >
> > Currently interpolation syntax used for freemarker template is ${...}.
> > This is the same as the interpolation syntax for template literal in
> javascript.
> > As a result, extra coding is needed to escape the interpolation
> expression for javascript coding with freemarker template.
> >
> > Propose to change the use of ${...} to [=...] for freemarker template.
> >
> > Reference:
> >
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
> >
> https://freemarker.apache.org/docs/dgui_misc_alternativesyntax.html#dgui_misc_alternativesyntax_interpolation
> >
> > Regards,
> > James
>
>
Re: Change ${...} to [=...] for freemarker template
Posted by Jacques Le Roux <ja...@les7arts.com>.
Hi James,
I see no problems with that: +1
Jacques
Le 12/12/2020 à 10:43, James Yong a écrit :
> Hi all,
>
> Currently interpolation syntax used for freemarker template is ${...}.
> This is the same as the interpolation syntax for template literal in javascript.
> As a result, extra coding is needed to escape the interpolation expression for javascript coding with freemarker template.
>
> Propose to change the use of ${...} to [=...] for freemarker template.
>
> Reference:
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
> https://freemarker.apache.org/docs/dgui_misc_alternativesyntax.html#dgui_misc_alternativesyntax_interpolation
>
> Regards,
> James