AppyPrinciplesGetting started
appy.pod Writing ODT templates The « from » clause

The POD statements presented so far, like if and for, are tied to a given part of the POD template (a text paragraph, a title, a table, a table row, etc) and condition how this part is rendered in the result (the if statement, for example, renders the part only if the related condition is True). This way to work has its limits. Indeed, you can't insert what you want into the result: you are forced to use the part of the document that is the target of the statement. Of course, in this part, you can still write funny things like Python expressions and statements, but it may not be sufficient.

This is why a special from clause may be added to every POD statement. A statement containing such a clause will replace the content of the targeted document part by the result of the from clause. This clause must specify a Python expression that must produce a valid chunk of ODT content.

In the example below, the statement has a from clause producing a simple paragraph.

In the result, the targeted paragraph has been replaced by the chunk of ODT content specified in the from expression. Note that the from clause MUST start on a new line in the comment. Else, it will be considered as part of the statement and will probably produce an error.

In this example, the special, absent statement is neither a if, nor a for... It is a null statement whose sole objective is to replace the target by the content of the from expression. But you can also add from clauses to if and for statements. Here is an example with a for statement.

Here's the result. Note that within the from clause you may use the iterator variable (i, in this case) defined by the for statement.

Actually, when you don't specify a from clause in a statement, POD generates an implicit from clause whose result comes from the ODT chunk that is the target of the statement.

I agree with you: these examples are not very useful. Moreover, it requires you to have some knowledge of the ODF syntax. You also have to take care about the namespaces you specify (text:, style:, fo:, etc): they must match the ones used in your POD template. But these examples illustrate how from clauses work and how you may go further by yourself if POD does not implement (yet ;-)) what you need.

In the following sections, much more useful use cases will be presented, in the form of built-in POD functions that you may use within from clauses. Indeed, a bunch of functions is inserted by default to every context given to the POD renderer.