Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^4: HTML - sharing design and logic

by saskaqueer (Friar)
on Jul 01, 2004 at 17:35 UTC ( #371183=note: print w/replies, xml ) Need Help??

in reply to Re^3: HTML - sharing design and logic
in thread HTML - separating design and logic

It makes the templates really, really ugly.

Depends on how you do it. Myself, I use Template Toolkit and right off the bat I created a widgets/ directory in my base template directory. This widgets directory contains a different template for each of the form fields (text inputs, textareas, radio buttons, select fields, etc). My select field template is exactly what is below. I'm not even sure now if the SET option.selected = '' line is needed. I think I had to add it because of some weird complication (perhaps the option.selected value wasn't being reset in each iteration of the loop?).

[% USE HTML %] [% DEFAULT size = 1 %] <select name="[% HTML.escape(name) %]" size="[% size %]" class="frmSel +ect"> [% FOREACH option = options %] [% SET option.selected = ''; SET option.selected = ' selected="selected"' IF option.value = += selected; DEFAULT option.label = option.value; %] <option value="[% HTML.escape(option.value) %]"[% option.selected +%]>[% HTML.escape(option.label) %]</option> [% END %] </select>

Now within any html template that wants to include a select field, all it takes it this simple include:

[% INCLUDE widgets/select.tmpl name="fav_flavour" selected="$fav_flavour" options=[ { value => 'Chocolate', label => 'brown stuff' }, { value => 'Vanilla', label => 'plain stuff' }, { value => 'Strawberry', label => 'red stuff' } ] %]

Replies are listed 'Best First'.
Re^5: HTML - sharing design and logic
by hardburn (Abbot) on Jul 01, 2004 at 18:56 UTC

    Myself, I use Template Toolkit . . .

    Increasing the complexity of the template isn't a real solution, because at that point you're no longer doing seperation of data and code, which is the whole point.

    send money to your kernel via the boot loader.. This and more wisdom available from Markov Hardburn.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://371183]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2017-03-23 07:39 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (283 votes). Check out past polls.