Repository: incubator-freemarker Updated Branches: refs/heads/2.3-gae fbd6fa5f9 -> 28ac1abe4
Manual: Updated FAQ item regarding modifiable hashes/sequences Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/28ac1abe Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/28ac1abe Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/28ac1abe Branch: refs/heads/2.3-gae Commit: 28ac1abe45ffaa0968e14406ba03e33f660648cd Parents: fbd6fa5 Author: ddekany <[email protected]> Authored: Mon Jan 9 14:28:28 2017 +0100 Committer: ddekany <[email protected]> Committed: Mon Jan 9 14:28:28 2017 +0100 ---------------------------------------------------------------------- src/manual/en_US/book.xml | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28ac1abe/src/manual/en_US/book.xml ---------------------------------------------------------------------- diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml index 0a4f9e5..fd3c204 100644 --- a/src/manual/en_US/book.xml +++ b/src/manual/en_US/book.xml @@ -26157,11 +26157,26 @@ End book</programlisting> anyway.</para> <para>Now, if you still say you need to modify sequences/hashes - directly with the FreeMarker template, here are two solutions, but - please read the warning after them:</para> + directly with the FreeMarker template, here are some solutions, + but please read the warning after them:</para> <itemizedlist> <listitem> + <para>You can access the Java API of a + <literal>java.util.Map</literal> with the help of the + <literal>api</literal> built-in, like + <literal>myMap?api.put(11, "eleven")</literal>. You will need + to get a <literal>Map</literal> from somewhere though (an FTL + hash literal like <literal>{}</literal> won't suffice, as it's + read only and doesn't support <literal>api</literal> either). + For example, you could expose a Java method or + <literal>TemplateMethodModelEx</literal> to the template that + returns a <literal>new LinkeHashMap()</literal>, so you can do + <literal><#assign myMap = + utils.newLinkedHashMap()></literal>.</para> + </listitem> + + <listitem> <para>You can write a <literal>TemplateMethodModelEx</literal> and <literal>TemplateDirectiveModel</literal> implementation that can modify certain types of sequences/hashes. Just @@ -26186,13 +26201,8 @@ End book</programlisting> <listitem> <para>A sequence can have some methods/directives if you use a - customized wrapper (so you can <literal><@myList.append foo - /></literal>). (Also, if you use - <literal>BeansWrapper</literal> and configure it so it exposes - the public methods, you can use the Java API for variables - that are for <literal>java.util.Map</literal>-s and - <literal>java.util.List-s</literal>. Just like with Apache - Velocity.)</para> + customized wrapper (so you can write something like + <literal><@myList.append foo /></literal>).</para> </listitem> </itemizedlist>
