Contents
Index
Search

12.1. Adding empty text nodes to your element templates

In some cases, you want the element template to contain an empty text node because, when a new element corresponding to this template is inserted in the document, the empty text node acts as a placeholder.

XHTML example:

<cfg:elementTemplate name="name_field">
  <p xmlns="http://www.w3.org/1999/xhtml"
     class="name_field"><b>Name: </b>   </p>
</cfg:elementTemplate>

The above element template should work fine. However all the whitespace following the b element will be automatically trimmed and no empty text node will inserted after it.

If you rewrite the above template as:

<cfg:elementTemplate name="name_field">
  <p xmlns="http://www.w3.org/1999/xhtml"
     class="name_field"><b>Name: </b><?text?></p>
</cfg:elementTemplate>

the element template will work as expected.

Note that the <?text?> processing instruction must be completely empty, otherwise it is inserted in the document as is. Also note that the <?text?> processing instruction must not follow or precede a text node (empty or not), otherwise it is simply discarded.