[Templates] Comments create newline characters

John Bida Bida.John at mayo.edu
Thu Jul 31 04:28:04 BST 2008


Using

[%- #Comment %]

Removed the newline character. Thanks for all the responses.

~Jp

On Jul 30, 2008, at 8:09 PM, C. Chad Wallace wrote:

>
> At 6:37 PM on 30 Jul 2008, John Bida wrote:
>
>> Is there a filter that removes the newline character that is created
>> by the template comments. For example, if you used the following two
>> files
>>
>>
>> textbox.tt
>> <html>
>> <textarea>[%PROCESS text.tt %]</textarea>
>> </html>
>>
>> text.tt
>> [% ## Some type of file header ###%]
>> [% ## Some type of file header ###%]
>> [% ## Some type of file header ###%]
>> [% ## Some type of file header ###%]
>> [% ## Some type of file header ###%]
>> Line 1
>> \n blank line
>> [% ## Comment ###%]
>> Line 2
>> [% ## Comment ###%]
>>
>> When the html is displayed Line 1 and  Line 2 are on the 6th and 9th
>> lines in the textarea. The comments in the template file are treated
>> as blank lines. I have tried the collapse filter, but it gets ride
>> of newline characters all together not just the ones caused by the
>> comments. I could write a perl program to act as a filter but I am
>> not sure how I can distinguish between the newlines created by the
>> comments and those that appear in the file. Any suggestions?
>
> Use dashes in your comment tags:
>
> [%- ## Comment ###%]
>
> The dashes can go at the beginning or the end, depending on where you
> want the white space to be chomped.  I find that doing it on both ends
> results in too much chomping, so I usually just put them at the
> beginning.
>
> See the 'Chomping Whitespace' section in perldoc
> Template::Manual::Syntax.
>
> -- 
>
> C. Chad Wallace, B.Sc.
> The Lodging Company
> http://www.skihills.com/
> OpenPGP Public Key ID: 0x262208A0
>
> Debian Hint #20: Want to keep track of what version of a package you
> have installed (especially useful for those running hybrid stable /
> testing / unstable systems)? Check out apt-show-versions.
> _______________________________________________
> templates mailing list
> templates at template-toolkit.org
> http://mail.template-toolkit.org/mailman/listinfo/templates




More information about the templates mailing list