For Programmers: Free Programming Magazines  


Home > Archive > PHP Smarty Templates > May 2004 > Re: [SMARTY] Re: Create wrapper for popup function with input from









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [SMARTY] Re: Create wrapper for popup function with input from
Tommy Ipsen

2004-04-28, 5:57 am

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.php


Exactly what I was looking for :-)

>
> you mean array elements?
>
> {foo attr=$array.key} or {$var|foo:$array.key} should just do fine.


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
* -------------------------------------------------------------
* 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
Jochem Maas

2004-04-30, 5:59 am

Hi Tommy,

I just answered your original question on this, before noticing this=20
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
>=20
>=20
>=20
> Exactly what I was looking for :-)
>=20
>=20
>=20
> I also got an email response from Monte Ohrt telling the following was =


> sufficient:
>=20
> {popuphelp linktext=3D$form.title.label ....
>=20
> Which resembles your first suggestion and works like a charm!
>=20
> All in all I ended up with the following:
> Extract from template:
>=20
> <td>{popuphelp linktext=3D$form.tpl_name.label header=3D"Pagename"=20
> helptext=3D"Helptext telling about pagename."=20
> helpitem=3D"helpitemidentifier"}</td>
> <td>{$form.tpl_name.html} {popuphelp linktext=3D$form.active.label=20
> header=3D"Active" helptext=3D"Helptext telling about active."=20
> helpitem=3D"helpitemidentifier"}{$form.active.html}</td>
>=20
> <?php
> /*
> * Smarty plugin
> * -------------------------------------------------------------
> * File: function.popuphelp.php
> * Type: function
> * Name: popuphelp
> * Purpose: wrapper for popup function to create customized help popup
> * -------------------------------------------------------------
> */
>=20
> function smarty_function_popuphelp($params, &$smarty) {
> // F=E5 fat i popup funktionen
> require_once($smarty->_get_plugin_filepath('function', 'popup'));
>=20
> // "Skabelon" for det generede hj=E6lpe-popup-link
> $popuplinktxt =3D '<a href=3D"/admin/ticmshelp.php?id=3D%1$s" class=

=3D"help"=20
> target=3D"ticmshelp" onclick=3D"link_popup(this);return false"=20
> %2$s>%3$s</a>%4$s';
>=20
> // Hvis der ikke er angivet en tekst til popupboksen, s=E6ttes den =

til=20
> None - m=E5 IKKE v=E6re tom!
> if (!isset($params['helptext']) || empty($params['helptext'])) {
> $params['helptext'] =3D 'None';
> }
>=20
> $postlinktext =3D '';
> // Split linkteksten, s=E5 der kun medtages til : (kolon)
> if (isset($params['linktext']) && !empty($params['linktext'])) {
> $strpos =3D strpos($params['linktext'], ':');
> if ($strpos !=3D=3D false) {
> $postlinktext =3D substr($params['linktext'], $strpos);
> $params['linktext'] =3D substr($params['linktext'], 0, $str=

pos);
> }
> }
> // Hvis der ikke er angivet en linktekst s=E6ttes denne til 'Hj=E6l=

p!'
> else {
> $params['linktext'] =3D 'Hj=E6lp!';
> }
>=20
> // Hvis der ikke er angivet et id p=E5 den =F8nskede hj=E6lp vil=20
> hovedsiden automatisk vises!
> if (!in_array('helpitem', array_keys($params))) {
> $params['helpitem'] =3D '';
> }
>=20
> // Parametre til popupboksen
> $popupparams =3D array('delay' =3D> '400', 'left' =3D> yes, 'offset=

x' =3D>=20
> 10, 'offsety' =3D> -50, 'text' =3D> $params['helptext']);
> if (in_array('header', array_keys($params))) {
> $popupparams['caption'] =3D $params['header'];
> }
> $popuptxt =3D smarty_function_popup($popupparams, $smarty);
> return sprintf($popuplinktxt, $params['helpitem'], $popuptxt,=20
> $params['linktext'], $postlinktext);
> }
> ?>
>=20
> Neat solutions are often very simple - I thank you both for your help!
>=20
> Have a nice one.
>=20
> Cheers, Tommy Ipsen
>=20

Tommy Ipsen

2004-05-04, 4:05 pm

Jochem Maas wrote:

> 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!


Well not quite on my own - I got help from Messju and Monte :-)

But thanks for your reply anyway - it made me consider error handling
and looking on the existing modules to see how they handle this! Being a
PEAR freak I'm also a bit into proper error handling :-)

Cheers, Tommy
Tommy Ipsen

2004-05-04, 4:05 pm

Jochem Maas wrote:

> 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!


Well not quite on my own - I got help from Messju and Monte :-)

But thanks for your reply anyway - it made me consider error handling
and looking on the existing modules to see how they handle this! Being a
PEAR freak I'm also a bit into proper error handling :-)

Cheers, Tommy
Boots

2004-05-04, 4:05 pm

--- Tommy Ipsen <tipsen@imada.sdu.dk> wrote:
> Being a PEAR freak I'm also a bit into proper error handling :-)


Off-topic, but I think that is one instance where "consistent" should
replace "proper" ;)

xo boots




__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs
http://hotjobs.sweepstakes.yahoo.com/careermakeover
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com