Re: including other FTL-template through model

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Thursday, February 5, 2009, 11:28:26 PM, aldana wrote:
>
> Daniel Dekany wrote:
>> 
>> Thursday, February 5, 2009, 3:19:59 PM, aldana wrote:
>>>
>>> Hi,
>>>
>>> usually to include other FTL I need to use <#include> directive. For
>>> special
>>> dynamic inclusion though I would like to do this directly through the
>>> backing Model java-class. 
>>>
>>> Is this possible in freemarker? (e.g. Tapestry5 supports building up page
>>> both in template file and java-type)
>> 
>> Certainly it's possible.
>> 
>> Where do the source code of those dynamically included templates come
>> from? When is it decided what their source code will be?
>> 
>> (a) [...] <#include theTemplateName>, where theTemplateName is a variable
>> in the
>> data-model.
>> 
>> 
>
> Thanks, I already went for the (a) option (great that #include directive
> offers string expression),

It's just like in Java or any other widely used programming
languages... a parameter can be any kind of expression, as far as the
end result is of the proper type.

> so it seems that freemarker first replaces the
> variables

and calculates with the operators too, like in the case of
<#include userBaseDir + "menu.ftl">

> and text strings

(a text string represents a final value, so there is nothing to
replace there)

> and after that goes to process the directives and macros.

Almost, but not exactly. Just before a directive or method is
executed, all parameters of it is calculated. Not earlier than that.
And if the same directive or method call is executed later again, then
the parameters will be calculated again. So for example, this:

  <#list ["a.ftl", "b.ftl", "c.ftl"] as templateName>
    <#include templateName>
  </#list>

does the same as

    <#include "a.ftl">
    <#include "b.ftl">
    <#include "c.ftl">

Well, just like in most other languages.

> -----
> manuel aldana
> aldana((at))gmx.de
> software-engineering blog: http://www.aldana-online.de

-- 
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.