[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Koha-devel] template system abuse
From: |
Pierrick LE GALL |
Subject: |
[Koha-devel] template system abuse |
Date: |
Thu, 13 Apr 2006 12:09:06 +0200 |
Hi koha-devel,
Having worked on several intranet template, I've seen things that make
me think we sometimes abuse of the HTML::Template toolkit. Apart from
the pagination bar I added recently, I propose 2 examples:
1. URL creation
===============
We want an URL like the following: "script.pl?key1=value1&key2=value2"
To achieve this, I've seen :
href="<!-- TMPL_VAR NAME="script_name" -->?firstkey=firstval&<!--
TMPL_LOOP NAME="url_params" --><!-- TMPL_VAR NAME="key" -->=<!--
TMPL_VAR NAME="val" -->&<!-- /TMPL_LOOP -->"
(everything on a single line, of course... enjoy the unreadability of
345 characters per line)
I really don't understand what we gain by building the URL in the
template... while we could do this beautifuly in Perl code before
sending to template:
$template->param(
url =>
$scriptname.'?'.
.join(
'&',
map { $_->{key}.'='.$_->{val} } @field_data
),
);
and in template:
href="<!-- TMPL_VAR NAME="url" -->"
2. "selected" option in SELECT
==============================
Each option of an HTML SELECT can be selected or not. Localization
mecanism forbids to have a TMPL_IF inside the <option> tag. So we need
something like:
<!-- TMPL_LOOP NAME="items" -->
<!-- TMPL_IF NAME="selected" -->
<option value="<!-- TMPL_VAR NAME="value" -->" selected="selected"><!--
TMPL_VAR NAME="name" --></option>
<!-- TMPL_ELSE -->
<option value="<!-- TMPL_VAR NAME="value" -->"><!-- TMPL_VAR NAME="name"
--></option>
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
The risk of typo is not negligible, the template can become huge with
many options (see
koha/koha-tmpl/intranet-tmpl/prog/en/circ/circulation.tmpl to
understand what I mean). Couldn't we simply have
<!-- TMPL_LOOP NAME="items" -->
<option value="<!-- TMPL_VAR NAME="value" -->" <!-- TMPL_VAR NAME="selected"
-->><!-- TMPL_VAR NAME="name" --></option>
<!-- /TMPL_LOOP -->
With in Perl script:
selected => (condition ? ' selected="selected"' : '')
My conclusion...
In my opinion, template system is useful for customization. The examples
above are no customization, they make templates heavier, less
readable... harder to customize. Do I miss something or do we really
need complicated templates on given examples?
Bye,
--
Pierrick LE GALL
INEO media system
- [Koha-devel] template system abuse,
Pierrick LE GALL <=