I can't show you the whole code, but the following are basically the steps I'm taking to generate dynamic code inside my fo-table-body tag.
At a stage inside <fo:table-body>
, I want to be able to reference the block named "ref" and change the value inside out if. Is this possible ?
<#assign value="Hello World"/>
<fo:block name"ref">
<fo:inline font-weight="bold">Value: </fo:inline>
<fo:inline>${Value}</fo:inline>
</fo:block>
<fo:table-body start-indent="0pt">
// All sorts of data inside the tags
<fo:table-row>
<fo:table-cell></fo:table-cell>
</fo:table-row>
</fo:table-body>
FreeMarker templates continuously write to the output as they are executed, so if you have already printed a piece of output, then it's not in the hands of FreeMarker anymore. (It might be still sitting in some buffer behind the Writer
, but FreeMarker is not aware of that.) What you can do though is generating the dependency part (fo:table-body
) first, but capturing it instead of printing it, like <#assign tableBody><fo:table-body...>...</fo:table-body></#assign>
, then generate the dependent part (fo:block
) as usual, then print the captured part (${tableBody}
, or <#noescape>${tableBody}</#noescape>
, depending on what kind of auto-escaping you use).