Discussion:
[FreeMarker-user] How to get the list of ftl files and their macros used to render the current ftl
Albert Kam
2014-04-12 02:06:42 UTC
Permalink
For example, in my current ftl, albert.ftl, is making use of several other
ftls, like :
layout.ftl, util.ftl, and other ftls that are imported but not necessarily
used.

Both layout.ftl and util.ftl also have many utility macros, and for
albert.ftl, i'm just using several like <@layout.layout>, or
<@layout.announcement>, or <@util.mybutton>, etc.

Is there any way that in my albert.ftl, i can 'print out' the content of
the ftl macros that are actually used ? And whether i can get the full
filepath to the ftl, so i can save the changes i make.

I'm hoping to achieve easy 'view and edit ftl source' to help me with
applying i18n on uni18n-ed texts, and to quick fix mistakes in the
production environment without having to ssh+vim on the server.

Regards from Jakarta,
Albert Kam
--
Do not pursue the past. Do not lose yourself in the future.
The past no longer is. The future has not yet come.
Looking deeply at life as it is in the very here and now,
the practitioner dwells in stability and freedom.
(Thich Nhat Hanh)
Daniel Dekany
2014-04-13 22:45:23 UTC
Permalink
layout.ftl, util.ftl, and other ftls that are imported but not necessarily used.
Both layout.ftl and util.ftl also have many utility macros, and for
Is there any way that in my albert.ftl, i can 'print out' the
content of the ftl macros that are actually used ?
There's nothing built in for that. You could walk the AST starting
with getRootTreeNode(), but it's a non-published API and as such can
change over time. Although the output of
TemplateElement.getCanonicalForm() is probably stable enough.
And whether i can get the full filepath to the ftl, so i can save
the changes i make.
Directly from the Template, you can't. It only remembers the path-like
template name, not the original source (which is not always a file).
OTOH if you have knowledge about where the templates are loaded from
(i.e., from the TemplateLoader setup), you can possibly deduce the
real path from the Template.getName().

BTW, associating the source of the template with the Template object
is on my TODO, but things go slowly nowadays...
I'm hoping to achieve easy 'view and edit ftl source' to help me
with applying i18n on uni18n-ed texts, and to quick fix mistakes in
the production environment without having to ssh+vim on the server.
Regards from Jakarta,
Albert Kam
--
Thanks,
Daniel Dekany
Loading...