Re: [SMARTY] Re: Create wrapper for popup function with input from PEAR_QuickForm!!??

From: Date: Tue, 27 Apr 2004 13:46:54 +0000
Subject: Re: [SMARTY] Re: Create wrapper for popup function with input from PEAR_QuickForm!!??
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-11312@lists.php.net to get a copy of this message
On Tue, Apr 27, 2004 at 03:35:05PM +0200, Tommy Ipsen wrote: > Hi again > > After reading my original (very confusing) posting and thinking more > about the problem, I was able to boil it down to the following two problems: > > Q1: How to correctly wrap an existing smarty modifier/function with my > own smarty modifier/function? > > A1: I've built the plugin below which is just a very "rough" solution to > the problem > > <?php > /* > * Smarty plugin > * ------------------------------------------------------------- > * File: function.popuphelp.php > * Type: function > * Name: popuphelp > * Purpose: wrapper for popup function to create customized help popup > * ------------------------------------------------------------- > */ > > function smarty_function_popuphelp($params, &$smarty) { > $popuplinktxt = '<a href="/admin/helppopup.php?id=%1$s" > class="help" target="ticmshelp" onclick="link_popup(this);return > false" > %2$s>%3$s</a>'; > if (!in_array('header', array_keys($params))) { > $params['header'] = ''; > } > if (!isset($params['helptext']) || empty($params['helptext'])) { > $params['helptext'] = 'None'; > } > if (!in_array('helpitem', array_keys($params))) { > $params['helpitem'] = ''; > } > if (!in_array('linktext', array_keys($params))) { > $params['linktext'] = 'LINK'; > } > > $popupparams = array('delay' => '400', 'left' => yes, > 'offsetx' => > 10, 'offsety' => 0, 'caption' => $params['header'], > 'text' => > $params['helptext']); > $popuptxt = smarty_function_popup3($popupparams, $smarty); > return sprintf($popuplinktxt, $params['helpitem'],$popuptxt, > $params['linktext']); > } > > function smarty_function_popup3($params, &$smarty) > { > ...all the code from smarty_function_popup copy/pasted... > } > > This is not very nice, but it's working - I can think of several > problems with the above method but I really can't figure out how to this > "correctly" ? $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.php > 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. > A2: I've read the SmartyFAQ at > > http://smarty.incutio.com/?page=SmartyFrequentlyAskedQuestions#template-5 > > and stumbled upon the use of the backtick operator (`) which seems to > solve my problem: > > var1="$form.title.label" > > Is this the correct way of solving this problem? > > Hope you can help me out with this simplified version of the original > problem! > > Cheers, Tommy Ipsen > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.smarty.general (#11312) next »