Re: Making a macro library part of a data model?
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Look at the freemarker.core.Environment API; it has an importLib
method, also setVariable and like. If you implement the feature with
TemplateDirectiveModel, you get the Environment object as method
parameter, otherwise you can get it with
Environment.getCurrentEnvironment().
Tuesday, March 29, 2011, 6:26:55 PM, Chris wrote:
> I've got a bit of an odd use-case.
>
> We've got a custom data model that changes behavior based on user
> parameters:
>
> [@aFancyDirective version="123"/]
>
> Depending on the version number, we want to import a particular macro
> library into a template so it's available to the designer.
>
> We had been doing it using Configuration.addAutoInclude(), but now that
> we need to implement different versions, it would be a lot cleaner for
> us to handle it in the data model.
>
> Right now, our data model looks like this:
>
> public class DataModel implements TemplateHashModel {
>
> public Object get(Object key) {
>
> if (key.equals("foo")) {
> return someStuff;
>
> } else if (key.equals("bar")) {
> return otherStuff;
> }
>
> }
> }
>
> We'd like to make it so that if key.equals("someMacro") then we can
> return the macro. Is it possible to load the macro library into a
> template, and then somehow find the macro in the template and return it
> in response to a get()?
>
>
> ------------------------------------------------------------------------------
> Enable your software for Intel(R) Active Management Technology to meet the
> growing manageability and security demands of your customers. Businesses
> are taking advantage of Intel(R) vPro (TM) technology - will your software
> be a part of the solution? Download the Intel(R) Manageability Checker
> today! http://p.sf.net/sfu/intel-dev2devmar
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar