A template is ordinary text with instructions in it. There are two, and everything a template does is built from them. An instruction is written as a tag in the namespace `invantive`. Everything outside such a tag is text and is left alone, so a `<` in the running text is no problem: only the exact text `<invantive:` puts the product into instruction mode, and that detection is case sensitive. ## value-of `<invantive:value-of />` replaces itself by a value. It is written in one of two ways: - `<invantive:value-of expression="..." />` prints the outcome of an [[Expressions|expression]]. - `<invantive:value-of querylabel="..." field="..." />` prints one column of the current row of a repetition, naming the repetition and the column separately. The two are interchangeable: `querylabel="pjt" field="pjt_code"` says the same as `expression="$V{pjt.pjt_code}"`. The first reads more easily in a template which repeats over one thing; the second is the one to use when the value has to be combined with something else. ## foreach `<invantive:foreach>...</invantive:foreach>` repeats the text between the two tags once for every row of a query. - `query`: the statement in [[Invantive UniversalSQL/Invantive UniversalSQL|Invantive UniversalSQL]] which yields the rows. - `alias`: the name by which the row is referred to inside the repetition, in `$V{alias.column}`. Repetitions may be nested, and that is where the alias earns its keep: the query of an inner repetition may use a value from the row of the outer one, which is how a list of projects with their cost centres underneath is written. A repetition which starts inside a table row and ends inside the same row repeats that row rather than the text within the cell, so a table which grows with the data is written by putting the two tags in the first and the last cell of the row to be repeated. ## Example The following template prints, per project within a product group asked of the user, the budget per cost centre: ``` In the list of projects below you see the budget per project within product group <invantive:value-of expression="$P{p_pgp_code}" />. <invantive:foreach alias="pjt" query="select pjt_code, pjt_city from projects_v where pgp_code=$P{p_pgp_code} order by pjt_sorting_order"> Project: <invantive:value-of querylabel="pjt" field="pjt_code"/> in <invantive:value-of expression="$V{pjt.pjt_city}"/>. The costs are: <invantive:foreach alias="csc" query="select ccr_code, csc_budget_amount from cost_centres_v where pjt_code = $V{pjt.pjt_code} order by ccr_code"> <invantive:value-of expression="$V{csc.ccr_code}" />: <invantive:value-of expression="$V{csc.csc_budget_amount}"/> </invantive:foreach> </invantive:foreach> ``` The outer repetition walks the projects; the inner one walks the cost centres of the project currently in hand, which it recognises through `$V{pjt.pjt_code}`. The parameter `p_pgp_code` is answered by the user before the document is composed; see [[Invantive Composition for Word/Modeller/Edit Model/Parameters|Parameters]].