Word and Excel templates fill themselves with list data in Teamsware Studio. This overview shows the syntax for formatting values, inserting images and links, repeating records and applying conditions.
Document creation runs through a triggered action: you store a Word or Excel template containing placeholders, and when the action fires they are replaced with the values of the given record. Placeholders always sit inside double square brackets.
π― At a Glance
[[Feldname]] inserts a value β the basic building block of every template.
[[{ β¦ }]] wraps a function when the value needs formatting or calculating before output.
For repetition and conditions there are the blocks [[loop]] und [[if]] β each with its matching closing tag.
π‘ The basic idea
Simple placeholder β insert the value unchanged
Function β prepare the value before output (currency, date, percentage β¦)
Block β output several records or tie content to a condition
Raw values from a list are rarely formatted the way they should appear in the document. A function prepares them:
| Purpose | Syntax |
|---|---|
| Currency with two decimals and euro sign | [[{return [[WaehrungAuto]].toFixed(2).replace(".", ",") + " β¬"}]] |
| Format a date | [[{return [[Datum]].format("yyyy-MM-dd")}]] |
| Percentage with sign | [[{return parseFloat(([[ZahlProzentsatz]]*100).toFixed(4)).toString().replace(".", ",") + " %"}]] |
The .replace(".", ",") produces the German decimal comma β without this step the value appears with a dot.
For a lookup field simply append a dot and the internal name of the column you want:
[[Lookup.Title]]
[[Lookup.Besitzer]]
A multi-choice field returns several values. To show them readably on one line, join them with a separator:
[[{return [[MultiAuswahl]].join("; ")}]]
Images are embedded through the image function β either at original size, at a fixed size or capped at a maximum size:
| Purpose | Syntax |
|---|---|
| Insert an image | [[image ([[Picture]])]] |
| Set width and height | [[image ([[Picture]], 50, 50)]] |
| Cap the maximum size | [[image ([[Picture]], maxwidth=100, maxheight=300)]] |
For links you decide whether just the URL, a link text from the field or a fixed text should appear:
| Purpose | Syntax |
|---|---|
| Link only | [[link ([[Hyperlink]])]] |
| Link with link text from the field | [[link ([[Hyperlink.Url]], [[Hyperlink.Description]])]] |
| Manually specified link text | [[link (url=[[Hyperlink.Url]], text='linktext')]] |
Rich text fields contain HTML formatting. To preserve it in the document β instead of showing it as code β output the field through the html function:
[[html ([[@Variables.CustomHTML]])]]
[[RichTextField]]
[[EnhancedRichTextField]]
[[html ([[Column]], inline=true)]]
[[html ([[Column]], true)]]
With inline=true the content is placed into the running text instead of creating its own paragraph.
To sum values from another list, retrieve them with a query and add them up inside the function:
[[{ var arr = [[@Web.GetValuesForQuery('OtherList', '<View></View>', 'Total')]]; var sum = 0; arr.forEach(n=>sum +=n); return sum; }]]
You provide the list name, the CAML query narrowing the records and the column to read.
With [[loop]] you repeat a section for each record. Loops can also be nested β for example to output the related items for each case:
Nested loops
[[loop]]
[[Title]]
[[loop SubList1]]
[[Lastname]]
[[Firstname]]
[[end loop]]
[[loop SubList2]]
[[Title]]
[[Nachtrag]]
[[end loop]]
[[end loop]]
Every loop needs its own [[end loop]]. Without a sublist specified, the loop runs over the records of the main list.
π‘ Loops inside tables
If each record should produce a table row, place [[loop]] und [[end loop]] inside the row that should be repeated:
[[loop]] [[Title]] β¦ [[end loop]]
The row is then generated once per record β the table formatting stays intact.
With [[if]] a section only appears when the condition is met. Otherwise the spot stays empty in the document.
| Condition | Syntax |
|---|---|
| Value 1 greater than value 2 (direct comparison) | [[if [[Budget]] > [[Outgoings]] ]] [[Title]] [[end if]] |
| Value 1 greater than value 2 (as a function) | [[if {return ([[Wert1]] > [[Wert2]]);} ]] [[Title]] [[end if]] |
| Choice does not equal a text | [[if [[Auswahl]]!="Auswahl1" ]] [[Title]] [[end if]] |
| Yes/no field is set | [[if [[JANein]]==true ]] [[Title]] [[end if]] |
Both notations for the comparison produce the same result. The variant using {return β¦} makes sense when the condition grows more complex and several checks need combining.
In the template the placeholders sit directly in the running text or in table cells β exactly where the value should later appear. Formatting such as font, size and emphasis is taken from the template by Teamsware Studio.
π― Teamsware recommendation
Build templates step by step instead of inserting all placeholders at once. That way an error is found right where it was introduced.
[[loop]]- und [[if]]block is closed properly.π‘ Quick reminder
[[Feld]] = insert a value
[[{ β¦ }]] = prepare a value
[[loop]] β¦ [[end loop]] = repeat
[[if]] β¦ [[end if]] = only when the condition applies
[[loop]]- oder [[if]]block open β the template then cannot be processed correctlyhtml function β the HTML code then appears as visible textTeamsware GmbH Β· LeopoldstraΓe 31 Β· 80802 MΓΌnchen Β· www.teamsware.eu