Text formatting in templates

< Metadata ${if} Statement >


Very frequently, you will be generating XML or HTML files and you won't be concerned with the appearance of the generated text. After all, the entire HTML or XML document could be in one line with no linefeeds at all and it would still display nicely in your browser.

Sometimes though, when you're generating plain text reports, you want some control over the format of the generated text. terp provides you with a number of options that allow you to control aspects like margins or linebreaking. Most of these controls are implemented as metadata options for embedded statements. Let's quickly revisit metadata: every embedded statement may contain metadata. Usually, you want to limit metadata to block statements, because the metadata assignment that you make remain valid for the block scope.

Let's look at a very simple example. You want to set the number of text columns for your document to 40; the default value is 80. Simply surround your template with


You also end up with an empty line at the beginning of your document because the closing } is followed by a linefeed. The easiest solution to this problem is to move the closing parenthesis to the next line, i.e.


What if you have a plain text file that contains text in the annoying "one paragraph per line" format and you would like to make it more readable?

${#width=40 #linebreak

The linebreak metadata element instructs terp to not exceed the specified linewidth when emitting text. This will break the one-line paragraphs in the input into multiple lines and make the text more readable.


Copyright 2006-2016 by Codemesh, Inc., ALL RIGHTS RESERVED

text layout
codemesh.com home expressions templates ant about us contact us download