Hallo and thank you!!
Yesterday I found the "setVariable"-Method in the Environment-Class and solved
my problem in this way:
SyndFeed feed = input.build(new XmlReader(httpCon));
BeansWrapper beanWrapper = new BeansWrapper(Configuration.VERSION_2_3_25);
BeanWrapper.setExposeFields(true);
BeanModel feedObj = new BeanModel(feed, beanWrapper);
env.setVariable(name, feedObj);
It works(!), but I will change it to your idea:
<#assign feed = readFeed("http://www.spiegel.de/einestages/index.rss")>
This looks clearer. Thank you!
Currenty I have the following problem and I am afraid that freemarker will
currently not support this:
I have one function called "a" and I have one custome derective called "b".
"a" has one paramter called "name" and "b" has a string parameter.
Now the following seems not to be possible:
<@a data="feed" markupProperty="${b("test")}"/>
The ferrmarker engine gives me a parse error and said "(" is not closed.
Is something like this possible or made i a mistake?
THANK YOU
Ingo
> Gesendet: Dienstag, 01. November 2016 um 19:51 Uhr
> Von: "Daniel Dekany" <[email protected]>
> An: "Ingo Mahnke" <[email protected]>
> Cc: [email protected]
> Betreff: Re: Call "assign" directive in a user-defined java directive
>
> 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
>
>