|
|
|
#1 (permalink) |
|
Messages: n/a
Hébergeur: |
Hello,
in various templates and multiple times within templates I have the following construct: {if is_array($TemplateVar.value) } <td>{html_options name=$TemplateVar.name options=$TemplateVar.value selected=$selected class="bg`$TemplateVar.farbe`" style="width:`$TemplateVar.breite`px" onchange=$TemplateVar.js}</td> {else} <td><input type="text" name="{$TemplateVar.name}" value="{$TemplateVar.value}" class="bg{$TemplateVar.farbe}" size="{$TemplateVar.breite}" {$TemplateVar.readstatus} /></td> {/if} I was wondering, whether there'd be a more convinient way to do that without performance loss. Would a plugin be a good idea? What (else) would you recommend?? Thanx in advance, Peggy |
|
|
|
#2 (permalink) |
|
Messages: n/a
Hébergeur: |
Hello again,
I solved the problem by writing a wee plugin which (dependent on the data type) calls either the smarty_function for select-box-creation or writes code for input field and returns it. ************in the template**************** <td>{checkfield data=$templateVar value=$templateVar_value selected=$selected}</td> ***************in function.checkfield.php*************** function smarty_function_checkfield($params, &$smarty) { if (is_array($params['value'])) { $res = smarty_function_html_options(array('name'=>$params['data']['name'], 'options'=>$params['value'], 'selected'=>$params['selected'], 'class'=>"bg" . $params['data']['farbe'], 'style'=>"width:" . $params['data']['breite'] . "px", 'onchange'=>$params['data']['js']),$smarty); } else { $res = "<input type=\"text\" name=\"" . $params['data']['name'] . "\" value=\"" . $params['value'] . "\" class=\"bg" . $params['data']['farbe'] . "\" size=\"" . $params['data']['breite'] . "\"" . $params['data']['readstatus'] . "/>"; } return $res; } ********************** Ciao, Peggy |
|
|
|
#3 (permalink) |
|
Messages: n/a
Hébergeur: |
Peggy Schatz wrote:
> ************in the template**************** > > <td>{checkfield data=$templateVar value=$templateVar_value > selected=$selected}</td> For what it's worth, you might also consider using a form handling class such as formsess, PEAR::HTML_QuickForm, etc. I use the latter, and my template code is something like this: <div{if $form.myelement.required} class="required"> <label for=$form.myelement.id>My Element Label</label> {$form.myelement.html} </div> The renderer object for the form takes care of outputting the correct markup for the input type. FWIW! -- Max Schwanekamp NeptuneWebworks.com 541-517-9064 |
|
![]() |
| Outils de la discussion | |
|
|