Re: Stripping blank lines caused by TMPL tags

Mitar <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.html-template
Message-ID <[email protected]>
Hi!

> This gets me the results I was looking for but feel that it is very much a
> kludge.  Have I missed something in the docs like a param for the
> constructor that automagicly does the same thing I have done minus me having
> to do anything?  Having seen the results of an HTML::Template minus the
> blank lines makes me want to see such results all the time without modifying
> my code and templates to do so.

I use this filter:

our $line_merger = sub {
	my $text_ref = shift;
	# Removes HTML comment style format from the tags (so that next regex works)
	$$text_ref =~ s/<!--\s*(~?\/?TMPL_.+?)\s*-->/<$1>/gis;
	# "Cleans" tags in such a way that it removes the space characters
and ~ (so if there is no ~ it does not
	# remove anything)
	$$text_ref =~ s/(?:\n[
\t]*(?=<~))?<~?(\/?TMPL_[^>~]+)~?(\/?)>(?:(?:(?<=~\/>)|(?<=~>))[
\t]*\n)?/<$1$2>/gis;
};

The idea is that I can use ~ character to specify that I want newline removed.

For example:

<~TMPL_VAR NAME="foo"~>

will remove newline before and after the tag (if there is any).

In most cases I use only second ~ as this efficiently (in most
template uses) removes all newlines after the tags and so there are no
empty lines in the output.


Mitar


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.