> Hmmmmm....I've been reading the manual and still after several
> iteration I can't seem to stumble on the right syntactical
> incantations to eliminate the whitespace to achieve the desired
> output. I'm using the version 2.04 downloaded from www.tt2.org.
The "[%-" and "-%]" chomp white space just before or just after
the directive. They do not chomp white space inside the directive.
For example: [%- " foo " -%] generates " foo ", not "foo".
The problem is that the files "a" and "img" end with a newline, which
won't be chomped by "[%-" or "-%]" when your do INCLUDE or WRAPPER.
There are several choices for getting rid of the newlines:
- Remove the trailing newline from the file. Not a good idea since
most editors will not let you, or complain or put it back, or someone
else will inadvently put it back.
- Put a block around the file contents, eg, your file "img" becomes:
---------------------------- img ----------------------------------
[% BLOCK %]<img src="example.gif" border="0">[% END -%]
----------------------------------------------------------------------
Note the trailing "-%]", which chomps the trailing newline. A similar
change to "a" gets rid of the other newline.
- Put the string inside the directive (turn it inside-out), again
with the trailing "-%]" (but this gets messy if the string is
more complicated):
---------------------------- img ----------------------------------
[% '<img src="example.gif" border="0">' -%]
----------------------------------------------------------------------
- Explicity trim the whitespace when you use INCLUDE or WRAPPER. Your
file "a" becomes (note: no need for "[%-" or "-%]" around content):
---------------------------- a -----------------------------------
<a href="myhref">[% content | trim %]</a>
----------------------------------------------------------------------
and test becomes:
---------------------------- test -----------------------------------
<td>
[%- FILTER trim %]
[% WRAPPER a %]
[% INCLUDE img %]
[% END %]
[% END -%]
</td>
----------------------------------------------------------------------
or:
---------------------------- test -----------------------------------
<td>
[%- FILTER trim;
WRAPPER a;
INCLUDE img | trim;
END;
END;
-%]
</td>
----------------------------------------------------------------------
- A hybrid approach is to have the WRAPPER file "a" handle everything,
using a combination of the above ideas:
---------------------------- a -----------------------------------
[% BLOCK %]<a href="myhref">[% content | trim %]</a>[% END -%]
----------------------------------------------------------------------
It trims the content, and makes sure there is no trailing newline.
Then "test could look like:
---------------------------- test -----------------------------------
<td>
[%- WRAPPER a; INCLUDE img; END; -%]
</td>
----------------------------------------------------------------------
This would be my preferred solution.
Craig