How to programatically find out what variables a template needs?

2 messages Options
Embed this post
Permalink
chrislusf

How to programatically find out what variables a template needs?

Reply Threaded More More options
Print post
Permalink
How to programatically find out what variables a template needs?

Let's say I have a template, and I want to get a list of variables the
template uses, and then prompt the user for the missing variables.

Is it possible?

Chris


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Daniel Dekany

Re: How to programatically find out what variables a template needs?

Reply Threaded More More options
Print post
Permalink
Monday, October 19, 2009, 11:03:20 AM, Chris Lu wrote:

> How to programatically find out what variables a template needs?
>
> Let's say I have a template, and I want to get a list of variables the
> template uses, and then prompt the user for the missing variables.
>
> Is it possible?

In short, no.

In detail, there are two problems here:

- The inherent problem: The language is too dynamic for that. You
  don't know what data-model variables will be get with
  .data[dynamicName], you don't know if which conditional parts will
  be executed, and, let's not forget, since data-model variables can
  be hidden (#assign, #global, #local...), it's at best difficult to
  tell if ${foo} refers to a data-model variable or not. And, of
  course, if call macros, those may refer to data-model variables
  internally too...

- Problems with the current API: For very trivial templates, you may
  try to make a good guess by traversing the template starting out
  with template.getRootTreeNode(), however, most node classes are not
  public, and I'm not sure how much can you reliably extract from the
  results of the common freemarker.core.TemplateElement methods.
  Anyway, this part of the API will be totally revisited in 2.4,
  exactly because it's lame in 2.3.x (but who knows when 2.4 will be
  released...). Plus, due to issues with Google App Engine we may will
  have to substitute the Swing API-s used by the mentioned 2.3 tree
  traversal API-s with our owns, which is then not backward-compatible
  (but otherwise easy to adapt to).

> Chris

--
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user