Re: How to get the list of ftl files and their macros used to render the current ftl

Daniel Dekany <[email protected]> Mon, 14 Apr 2014 00:45:23 +0200
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Saturday, April 12, 2014, 4:06:42 AM, Albert Kam wrote:

> 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 ?

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


------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment 
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees