Rendering

Post parsing of the templar files, the next step is rendering of the output.

try {
    String render = parser.render(templarContext);
    // do something with the rendered content...
    System.out.println(render);
} catch (RenderException rex) {
    rex.printStackTrace();
}

Some notes on rendering

1. Rendering the contents of a file...

You may render the contents of a file in one of two ways:

  1. {import path/to/file.extension} which will import and parse the file for templar declarations
  2. {static path/to/file.extension} which will output the file as is
2. Ignoring templar directives...

Need to output content as is (with new-lines/tabs and all sorts of characters including templar declarations)?

Use the {pre ... pre} templar declarations - in this you may put any characters (including the { and } character)

Inside a pre declaration, you may write whatever you want, including declarations {hello}, functions {fn:notNull[hello]} or anything else, this will be ignored by the templar parser

3. Whitespace and sentences over multiple lines...

This paragraph:

<p>
	sometimes
	have
	a
	sentence
	which
	is
	all
	strung
	together
</p>

Will turn into:

sometimeshaveasentencewhichisallstrungtogether

Whilst the following paragraph:

<p>
	When 
	you 
	really 
	wanted 
	it 
	not 
	to 
	do 
	that?
</p>

Will display correctly

When you really wanted it not to do that?

Ensure that you have a whitespace character ' ' at the end of each line, to ensure that the spacing is correct. (templar does NOT strip away the end of line whitespace - only the whitespace at the start of the line).

4. Non-existent items in the context...

If an item that you are trying to look-up does not exist, the for example: {hello}, you will see the following stacktrace:

[ FATAL ]: Could not parse file 'src/rendering.html'. Exception[ synapticloop.templar.exception.RenderException ] message was: Could not render line: hello
synapticloop.templar.exception.RenderException: Could not render line: hello

If you are expecting it, you will need to add this to the context, if it is variable as to whether this may exist in the context, you may wrap it in a fn:notNull function:

{if fn:notNull[hello]}
	'hello' is in the context
{else}
	'hello' is NOT in the context
{endif}

Which will render, as expected:

'hello' is NOT in the context