Hi,
It's doable (see later), but first I would like point out that doing
assignments inside custom directives is very often a disadvantageous
approach. If you need to produce a value, then use a method
(function), which if you are implementing it in Java, will be a
TemplateMethodModelEx implementation. Then you can do this:
<#assign feed = readFeed("http://www.spiegel.de/einestages/index.rss")>
and also you can do <#local feed = readFeed(...)>, <#list
readFeed(...).entries as entry>, etc., because readFeed(...) is just
an expression that can be put anywhere. (The places where directives
can be used are much more limited, and they aren't meant to produce
values.)
If you still want to do an assignment, then in the freemarker.core.Environment
object (which you get as argument if it's a TemplateDirectiveModel)
there's a setVariable(String name, TemplateModel model) method that
does what #assign do.
Monday, October 31, 2016, 9:13:18 PM, Ingo Mahnke wrote:
> Hallo!
>
> Maybe someone can help me:
>
> I wrote a user-defined directive in java, called "readFeed".
>
> In the template I write the following:
>
> <@readFeed name="feed"
> source="http://www.spiegel.de/einestages/index.rss" />
>
> My whish is to use the word "feed" as a normal variable
> (Type:SyndFeed) and I want to be able to write something like this:
>
> <#list entry as feed.entries>
> .........
> </#list>
>
> The question:
> How can I call the "assign" directive within my java code of my
> "ReadFeed" directive to create a freemarker variable of name "feed"?
>
> Thank you very much
> Ingo
>
>
>
>
>
--
Thanks,
Daniel Dekany