On Thu, 6 Jun 2002, Perrin Harkins wrote:

> For posterity, and possible inclusion in the next rev of the templating
> tutorial, how would you recommend people handle this sort of situation
> without using HTML::Template::Expr?
>
> Suppose you have a model object for a concert which includes a date.  On
> one page, the designers want to dipslay the date in a verbose way with
> the month spelled out, but on another they want it abbreviated and fixed
> length so that dates line up nicely.  Would you put that formatting in
> the controller?

In the script:

   $template->param(long_date  => $long_date,
                    short_date => $short_date);

In the template:

   The long date: <tmpl_var long_date>  <br>
   The short date: <tmpl_var short_date>

> What if you had a model object that generates a list of these concerts,
> and on a certain page the designers want to show it in two columns.
> Would you split it into two arrays in the controller?

I'm not sure I understand what you mean.  You're asking about how to flow
a list between two columns?  With vanilla HTML::Template that would
requrie a small amount of work in the script.  Either there would need to
be a column_break variable thrown in at the appropriate place or two
separate loops.  I think I would prefer the former.  In the template that
would look like:

  <table><tr>
    <tmpl_loop concerts>
       <tmpl_if column_break> </tr><tr> </tmpl_if>
       <td> <tmpl_var long_date> </td>
    </tmpl_loop>
  </tr></table>

In the script you'd just set the column_break in the appropriate row (or
rows for a multi-column layout).

Is that a point in favor of scripting in the templates?  Perhaps.  Of
course by limiting the power of template syntax I've made some things more
difficult.  If simple things should be simple and hard things should be
possible then not everything can be simple!

-sam


Reply via email to