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

HTML::TreeBuilder and HTML::Template

Stefan Svensson
June 3, 2003 02:18
HTML::TreeBuilder and HTML::Template
Message ID:
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>


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

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?



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:
906 41 UmeƄ, Sweden                 ICQ: 1956984 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About