How do I fit in a long field name or expression?

A key advantage of Docmosis is that a field name <<fieldname1>> can be typed straight into the template, between a pair of angled brackets  - doing away with the need for any special Word plugins. Docmosis substitutes data for the field names.

If the field name is long, or forms part of a lengthy expression, it can be tricky to fit this into a fixed-size table cell, or into a short paragraph.

This article explains how to work with extra long field names or expressions in your Word template.

Fitting a field name into a table cell

Sometimes a field name is too long to fit into a table cell in the template, where the data itself fits perfectly in the finished document.

Take these steps to fit a long field name or expression into a small, fixed-size table cell:

  • First, fix the cell size so that it will look right in the finished document, taking into consideration the sort of values that will be provided in the data. 

Note: To fix a cell size, right-click on the cell and select Table Properties. In the Row tab, specify a height, and select Row height is: Exactly. Next, click Autofit in the table's Layout ribbon tab, and select FixedColumnWidth from the drop-down.

  • Next, type out the cell contents in a text editor such as Notepad. In the example here, we have a dollar sign followed by the field name, which is enclosed in double angled brackets.

  • Copy and paste from Notepad into the table cell. As shown in the image below, only a section of the cell contents is visible in the cell because of its fixed size.

To view/edit the contents of a fixed-size cell such as this one, select the cell contents (Select > Select Cell on the Table Layout ribbon tab), then copy and paste into Notepad.

Using variables for a long expression

Expressions in Docmosis can be quite lengthy, because of the formatting notation and the field names used to build them. 

Variables are a good way to deal with long expressions. In the example below, a lengthy string expression is assigned to a variable. The variable is displayed on a new line, taking up minimal space.

Follow this technique to manage a long expression:

  1. Build a string expression by combining several field names: <<{title + ' ' + firstName + ' ' + lastName + ', ' + institution} >>
  2. To keep the result more useable, assign the string expression to a variable: <<$personalDetails= {title + ' ' + firstName + ' ' + lastName + ', ' + institution} >>
  3. Display the variable: <<$personalDetails>>

Data is inserted into the field names when Docmosis generates the document.

The resultant variable, made up of the different data values, is displayed in the finished document.

Storing a formatted date in a variable

Date formatting is also often used in Docmosis templates. In the example below, the current date $nowUTC (which is a built-in Docmosis variable for the current UCT time) is formatted and stored in a variable called $today, for use within the template.

The formatted date appears in the rendered document.

Advantages of using a variable 

This technique has several advantages:

  • The variable name can be short, and therefore easy to fit into a paragraph or table cell.
  • The variable can be used multiple times within the template (at any point in the template after the declaration).
  • The variable can be formatted as it should appear in the finished document, whereas the expression can have any font that is convenient for template maintenance and readability (e.g. a tiny font in light grey), as it does not appear in the finished document. 

Using a declarations page for multiple complex expressions

In the case where multiple complex expressions are required to manipulate field names within a template, it can be useful to keep these in a separate page within the template. 

This should be the first page of the template, so that subsequent pages can use the variables in the desired layout.

Note: If the declarations page only consists of expressions and comments, with nothing at all displayed, then the page itself will not appear in the finished document.

Use cases

These articles have example templates that deal with long field names or expressions: 

  • Account Statement: In this example, the field names are copied into table cells where they are not fully visible in the template. See the section "Designing for the finished document".
  • Insurance Certificate: In this example, the entire first page is dedicated to formatting the data. See the section "Using a declarations page".
  • One-Page Marketing Flyer: In this example, a string expression is used to format separate address lines into a single address variable. See the section "Using string expressions".


Invalid Input

Sorry, this field will only accept letters and numbers, and not special characters, to limit spam. Please also consider contacting if you need help with this article.

Sorry, this field will only accept letters and numbers, and not special characters, to limit spam.

Invalid Input