Re: [SMARTY] Re: Create wrapper for popup function with input from PEAR_QuickForm!!??
| From: | Jochem Maas | Date: | Thu, 29 Apr 2004 18:04:32 +0000 |
| Subject: | Re: [SMARTY] Re: Create wrapper for popup function with input from PEAR_QuickForm!!?? | ||
| References: | 1 2 3 4 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-11322@lists.php.net to get a copy of this message | ||
Hi Tommy,
I just answered your original question on this, before noticing this thread - anyway I see that you basically figured out for yourself how to
create a plugin to do what you needed.
I just wanted to say good on ya!
Tommy Ipsen wrote:
Hi Messju$smarty->_get_plugin_filepath('function', 'popup'); $popuptxt = smarty_function_popup($popupparams, $smarty); that's the suggested way, see here: http://smarty.php.net/manual/en/plugins.writing.phpExactly what I was looking for :-)I also got an email response from Monte Ohrt telling the following was sufficient: {popuphelp linktext=$form.title.label .... Which resembles your first suggestion and works like a charm! All in all I ended up with the following: Extract from template: <td>{popuphelp linktext=$form.tpl_name.label header="Pagename" helptext="Helptext telling about pagename." helpitem="helpitemidentifier"}</td> <td>{$form.tpl_name.html} {popuphelp linktext=$form.active.label header="Active" helptext="Helptext telling about active." helpitem="helpitemidentifier"}{$form.active.html}</td> <?php /* * Smarty plugin * -------------------------------------------------------------Q2. How to correctly pass array variables as input for a modifier/function?you mean array elements? {foo attr=$array.key} or {$var|foo:$array.key} should just do fine.* File: function.popuphelp.php * Type: function * Name: popuphelp* Purpose: wrapper for popup function to create customized help popup * ------------------------------------------------------------- */ function smarty_function_popuphelp($params, &$smarty) {// Få fat i popup funktionen require_once($smarty->_get_plugin_filepath('function', 'popup'));// "Skabelon" for det generede hjælpe-popup-link $popuplinktxt = '<a href="/admin/ticmshelp.php?id=%1$s" class="help" target="ticmshelp" onclick="link_popup(this);return false" %2$s>%3$s</a>%4$s';// Hvis der ikke er angivet en tekst til popupboksen, sættes den til None - må IKKE være tom! if (!isset($params['helptext']) || empty($params['helptext'])) { $params['helptext'] = 'None'; }$postlinktext = ''; // Split linkteksten, så der kun medtages til : (kolon) if (isset($params['linktext']) && !empty($params['linktext'])) { $strpos = strpos($params['linktext'], ':'); if ($strpos !== false) { $postlinktext = substr($params['linktext'], $strpos); $params['linktext'] = substr($params['linktext'], 0, $strpos); } } // Hvis der ikke er angivet en linktekst sættes denne til 'Hjælp!' else { $params['linktext'] = 'Hjælp!'; }// Hvis der ikke er angivet et id på den ønskede hjælp vil hovedsiden automatisk vises! if (!in_array('helpitem', array_keys($params))) { $params['helpitem'] = ''; }// Parametre til popupboksen $popupparams = array('delay' => '400', 'left' => yes, 'offsetx' => 10, 'offsety' => -50, 'text' => $params['helptext']); if (in_array('header', array_keys($params))) { $popupparams['caption'] = $params['header']; } $popuptxt = smarty_function_popup($popupparams, $smarty); return sprintf($popuplinktxt, $params['helpitem'], $popuptxt, $params['linktext'], $postlinktext);} ?> Neat solutions are often very simple - I thank you both for your help! Have a nice one. Cheers, Tommy Ipsen