develooper Front page | perl.libwww | Postings from June 2003

HTML::TreeBuilder and HTML::Template

From:
Stefan Svensson
Date:
June 3, 2003 02:18
Subject:
HTML::TreeBuilder and HTML::Template
Message ID:
Pine.LNX.4.44.0306031104581.1912-100000@dumburken.raggmunk.nu
Hello list,

Has anyone managed to teach HTML::TreeBuilder the syntax of HTML::Template 
(se man page om CPAN)?

The syntax of HTML::Template is quite simple and consists of <tmpl_if>,
<tmpl_unless>, <tmpl_loop> and the empty elements <tmpl_var> and
<tmpl_else> (only in an tmpl_if or tmpl_unless tag).  The problem is that
the template tags can occur just about anywhere in the HTML tree.

I have succeeded in some aspects by tweaking the tables in HTML::Tagset, 
but there are still many situations where HTML::TreeBuilder breaks the 
HTML::Template syntax.

Some examples:

1. <tmpl_loop> and <tmpl_if> within <select> and <table> sections does not 
   work properly, as HTML::TreeBuilder closes <tmpl>-tags and implicitly 
   adds <select>. Example:

   <select name="mooh">
     <tmpl_loop name="alternatives">
       <option><tmpl_var name="name"></option>
     </tmpl_loop>
   </select>

   Becomes:

   <select name="mooh">
     <tmpl_loop name="alternatives">
       <select>
         <option><tmpl_var name="name"></option>
       </select>
     </tmpl_loop>
   </select>

2. HTML::TreeBuilder escapes anything in a <textarea>, which does not work 
   when I want a <tmpl>-tag within the <textarea> tag.

My questions are: Has anyone done this? What is needed to make 
HTML::TreeBuilder accept the HTML::Template syntax? Some simple 
subclassing, or a major rewrite?

Regards,

Stefan

PS: HTML::Template and HTML::TreeBuilder is still compatible, since all 
template tags can be written as comments (<!-- tmpl_var name="spam" -->), 
but this does not give me the possibility of syntax checking and other 
HTML::Tree advantages.

-- 
Stefan Svensson                     Phone: +46-90-135000
Himlastigen 14                      WWW: http://raggmunk.nu/~stefan/
906 41 UmeƄ, Sweden                 ICQ: 1956984





nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About