[jira] [Commented] (FREEMARKER-83) Introduce new special variable "outer_template_name" beside "main_template_name"
[ https://issues.apache.org/jira/browse/FREEMARKER-83?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16394734#comment-16394734 ] Yanming Zhou commented on FREEMARKER-83: Thanks!! > Introduce new special variable "outer_template_name" beside > "main_template_name" > > > Key: FREEMARKER-83 > URL: https://issues.apache.org/jira/browse/FREEMARKER-83 > Project: Apache Freemarker > Issue Type: Improvement > Components: engine >Affects Versions: 2.3.27-incubating >Reporter: Yanming Zhou >Priority: Major > Fix For: 2.3.28-incubating > > > for example, a.ftl include b.ftl, b.ftl include c.ftl > || ||current_template_name||outer_template_name||main_template_name|| > |a.ftl|a.ftl|null|a.ftl| > |b.ftl|b.ftl|a.ftl|a.ftl| > |c.ftl|c.ftl|b.ftl|a.ftl| > I need such feature to resolve relative path like <#include> directive. > BTW: > .current_template_name is lazy evaluation, is this designed or bug > {code:title=b.ftl} > <#function templateName value> > <#return value/> > > {code} > {code:title=a.ftl} > <#include "b.ftl"> > ${templateName(.current_template_name)} > {code} > it will print "b.ftl" not "a.ftl", workaround: > {code:title=a.ftl} > <#include "b.ftl"> > <#assign current_template_name=.current_template_name> > ${templateName(current_template_name)} > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (FREEMARKER-83) Introduce new special variable "outer_template_name" beside "main_template_name"
[ https://issues.apache.org/jira/browse/FREEMARKER-83?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16394318#comment-16394318 ] Daniel Dekany commented on FREEMARKER-83: - OK, the related new thing is {{someName?absolute_template_name(baseName)}}, which converts {{someName}} to an absolute name, using {{baseName}} to resolve a relative path. So here's all related new features working together: {code:java} <#-- <@smileyInclude name /> behaves like <#include name>, but prints a "(:" before the template, or prints "):" instead if the template is missing. Note that just like with #include, if name is relative, it's resolved based on the directory of the caller template, not of the template that defines this macro. As .get_optional_template resolves relative names based on the current template, we had to convert the name to an absolute name based on the caller template before passing it to it. --> <#macro smileyInclude name> <#local t = .get_optional_template( name?absolute_template_name(.caller_template_name))> <#if t.exists> (: <@t.include /> <#else> ): {code} > Introduce new special variable "outer_template_name" beside > "main_template_name" > > > Key: FREEMARKER-83 > URL: https://issues.apache.org/jira/browse/FREEMARKER-83 > Project: Apache Freemarker > Issue Type: Improvement > Components: engine >Affects Versions: 2.3.27-incubating >Reporter: Yanming Zhou >Priority: Major > Fix For: 2.3.28-incubating > > > for example, a.ftl include b.ftl, b.ftl include c.ftl > || ||current_template_name||outer_template_name||main_template_name|| > |a.ftl|a.ftl|null|a.ftl| > |b.ftl|b.ftl|a.ftl|a.ftl| > |c.ftl|c.ftl|b.ftl|a.ftl| > I need such feature to resolve relative path like <#include> directive. > BTW: > .current_template_name is lazy evaluation, is this designed or bug > {code:title=b.ftl} > <#function templateName value> > <#return value/> > > {code} > {code:title=a.ftl} > <#include "b.ftl"> > ${templateName(.current_template_name)} > {code} > it will print "b.ftl" not "a.ftl", workaround: > {code:title=a.ftl} > <#include "b.ftl"> > <#assign current_template_name=.current_template_name> > ${templateName(current_template_name)} > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (FREEMARKER-83) Introduce new special variable "outer_template_name" beside "main_template_name"
[ https://issues.apache.org/jira/browse/FREEMARKER-83?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16394089#comment-16394089 ] Daniel Dekany commented on FREEMARKER-83: - It's outside the scope of this issue, but I plan to implement something like {{.to_absolute_template_name(basePath, maybeRelativePath)}}, so that when you want to implement something like {{#include}} with a macro using {{.caller_template_name}} as the base path, then you don't have to do implement the necessary logic in the template language. It's not entirely trivial due to absolute paths like {{foo://bar}}. > Introduce new special variable "outer_template_name" beside > "main_template_name" > > > Key: FREEMARKER-83 > URL: https://issues.apache.org/jira/browse/FREEMARKER-83 > Project: Apache Freemarker > Issue Type: Improvement > Components: engine >Affects Versions: 2.3.27-incubating >Reporter: Yanming Zhou >Priority: Major > Fix For: 2.3.28-incubating > > > for example, a.ftl include b.ftl, b.ftl include c.ftl > || ||current_template_name||outer_template_name||main_template_name|| > |a.ftl|a.ftl|null|a.ftl| > |b.ftl|b.ftl|a.ftl|a.ftl| > |c.ftl|c.ftl|b.ftl|a.ftl| > I need such feature to resolve relative path like <#include> directive. > BTW: > .current_template_name is lazy evaluation, is this designed or bug > {code:title=b.ftl} > <#function templateName value> > <#return value/> > > {code} > {code:title=a.ftl} > <#include "b.ftl"> > ${templateName(.current_template_name)} > {code} > it will print "b.ftl" not "a.ftl", workaround: > {code:title=a.ftl} > <#include "b.ftl"> > <#assign current_template_name=.current_template_name> > ${templateName(current_template_name)} > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (FREEMARKER-83) Introduce new special variable "outer_template_name" beside "main_template_name"
[ https://issues.apache.org/jira/browse/FREEMARKER-83?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16248531#comment-16248531 ] Yanming Zhou commented on FREEMARKER-83: Agree with "caller_template_name" > Introduce new special variable "outer_template_name" beside > "main_template_name" > > > Key: FREEMARKER-83 > URL: https://issues.apache.org/jira/browse/FREEMARKER-83 > Project: Apache Freemarker > Issue Type: Improvement > Components: engine >Affects Versions: 2.3.27-incubating >Reporter: Yanming Zhou > > for example, a.ftl include b.ftl, b.ftl include c.ftl > || ||current_template_name||outer_template_name||main_template_name|| > |a.ftl|a.ftl|null|a.ftl| > |b.ftl|b.ftl|a.ftl|a.ftl| > |c.ftl|c.ftl|b.ftl|a.ftl| > I need such feature to resolve relative path like <#include> directive. > BTW: > .current_template_name is lazy evaluation, is this designed or bug > {code:title=b.ftl} > <#function templateName value> > <#return value/> > > {code} > {code:title=a.ftl} > <#include "b.ftl"> > ${templateName(.current_template_name)} > {code} > it will print "b.ftl" not "a.ftl", workaround: > {code:title=a.ftl} > <#include "b.ftl"> > <#assign current_template_name=.current_template_name> > ${templateName(current_template_name)} > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029)
[jira] [Commented] (FREEMARKER-83) Introduce new special variable "outer_template_name" beside "main_template_name"
[ https://issues.apache.org/jira/browse/FREEMARKER-83?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16247623#comment-16247623 ] Daniel Dekany commented on FREEMARKER-83: - It should be rather `.caller_template_name`, I think. > Introduce new special variable "outer_template_name" beside > "main_template_name" > > > Key: FREEMARKER-83 > URL: https://issues.apache.org/jira/browse/FREEMARKER-83 > Project: Apache Freemarker > Issue Type: Improvement > Components: engine >Affects Versions: 2.3.27-incubating >Reporter: zhouyanming > > for example, a.ftl include b.ftl, b.ftl include c.ftl > || ||current_template_name||outer_template_name||main_template_name|| > |a.ftl|a.ftl|null|a.ftl| > |b.ftl|b.ftl|a.ftl|a.ftl| > |c.ftl|c.ftl|b.ftl|a.ftl| > I need such feature to resolve relative path like <#include> directive. > BTW: > .current_template_name is lazy evaluation, is this designed or bug > {code:title=b.ftl} > <#function templateName value> > <#return value/> > > {code} > {code:title=a.ftl} > <#include "b.ftl"> > ${templateName(.current_template_name)} > {code} > it will print "b.ftl" not "a.ftl", workaround: > {code:title=a.ftl} > <#include "b.ftl"> > <#assign current_template_name=.current_template_name> > ${templateName(current_template_name)} > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029)
[jira] [Commented] (FREEMARKER-83) Introduce new special variable "outer_template_name" beside "main_template_name"
[ https://issues.apache.org/jira/browse/FREEMARKER-83?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16247617#comment-16247617 ] Daniel Dekany commented on FREEMARKER-83: - That "lazy" thing is a bug... It's actually not a lazy evaluation issue, but that by the time the argument list expressions are evaluated, the invoked `#function` is already in the FTL call stack, and `.currentTemplateName` looks at the top of the FTL call stack to figure out where's it called from... ugh. I'm not even sure if I dare to fix this with `incompatible_improvements` set to 2.3.28, as it's quite backward incompatible to do, but maybe. > Introduce new special variable "outer_template_name" beside > "main_template_name" > > > Key: FREEMARKER-83 > URL: https://issues.apache.org/jira/browse/FREEMARKER-83 > Project: Apache Freemarker > Issue Type: Improvement > Components: engine >Affects Versions: 2.3.27-incubating >Reporter: zhouyanming > > for example, a.ftl include b.ftl, b.ftl include c.ftl > || ||current_template_name||outer_template_name||main_template_name|| > |a.ftl|a.ftl|null|a.ftl| > |b.ftl|b.ftl|a.ftl|a.ftl| > |c.ftl|c.ftl|b.ftl|a.ftl| > I need such feature to resolve relative path like <#include> directive. > BTW: > .current_template_name is lazy evaluation, is this designed or bug > {code:title=b.ftl} > <#function templateName value> > <#return value/> > > {code} > {code:title=a.ftl} > <#include "b.ftl"> > ${templateName(.current_template_name)} > {code} > it will print "b.ftl" not "a.ftl", workaround: > {code:title=a.ftl} > <#include "b.ftl"> > <#assign current_template_name=.current_template_name> > ${templateName(current_template_name)} > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029)