You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Roger Espel Llima <es...@iagora.net> on 2000/07/27 12:57:32 UTC

Re: Templating System

Darko Krizic <DK...@ProDyna.de> wrote:
> ... 
> <table id="results">
>       <tr id="resultheader">
>               <th>Name</th>
>               <th>Count</th>
>       </tr>
>       <tr id="singlerow>
>               <td id="row_name">example name</td>
>               <td id="row_count">example count</td>
>       </tr>
> </table>
> ...
> The problem with many templating systems is the fact that they invent a new
> language like "<td>$variable</td>" which is usually not displayable in the
> Browser so that the designer and the programmer must work tightly.

The designer has to learn 'id="row_name"' in one case, and $row_name in
the other.  I'd say that the need to work tightly with the programmer is
pretty much the same: you have to agree on a syntax for gaps that code
can fill, and on the names of the individual gaps.

> What other templating systems do exists that are usefull?

There is a real plethora of templating modules: the Template Toolkit,
HTML::Mason, HTML::DynamicTemplate, Text::TagTemplate and HTML::Template
can all do things like these.

They often differ in the calling approach: does the URL map to a script
which inits and calls a template object giving it values, or does the
URL map to the final template, which calls perl code to fill the gaps?
Within this there are many approaches too, different ways to draw the
line between what goes in the perl and what goes in the template, and
what kind of object model (if any) they implement.

I'm just about to release (next week) a templating/content-handling
module for mod_perl, called iAct, which takes the approach that URLs map
to template files, which call perl if they want, but then the perl code
can also manipulate templates and sections.  I'm not saying this is
necessarily the most appropriate for you, just letting people know about
it :) 

Under iAct, you'd do it like this:

<table>
  <tr>
    <th>Name</th>
    <th>Count</th>
  </tr>
  <% section "one_row" %>
    <tr>
      <td><$ row_name $>
      <td><$ row_count $>
    </tr>
  <% /section %>
  <% call sub="Your::Module::fill_rows" repeat="one_row" %>
</table>

and the code for Your::Module::fill_rows would be something like:

sub fill_rows {
  my ($self, $args) = @_;
  my ($sec, $ret) = ($args->{repeat}, "");
  foreach my $nc (&get_name_counts()) {
    $self->assign_raw(row_name  => $nc->[0],
		      row_count => $nc->[1]);
    $ret .= $self->fetch($sec);
  }
  $ret;
}

-- 
Roger Espel Llima, espel@iagora.net
http://www.iagora.com/~espel/index.html