Re: [SMARTY-DEV] Support for NULL in Smarty?!
| From: | Andr� Rabold | Date: | Wed, 19 Feb 2003 15:24:15 +0000 |
| Subject: | Re: [SMARTY-DEV] Support for NULL in Smarty?! | ||
| References: | 1 2 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-735@lists.php.net to get a copy of this message | ||
Hi Monte,
> Try CVS first, I think the true/false 0/1 issue is already patched.
The patch below applies to the newest CVS from ~ 3:00 p.m.
> As for null, example of what you want to do?
For example a function: (simplified)
smarty_function_buildURL ($params, &$smarty)
$url = array();
if (isset($params["params"]))
$url = $params;
foreach ($params as $key => $value) {
if ($key == "params") continue;
if (is_null($params[$key]))
unset($url[$key]);
else
$url[$key] = $value;
}
// [...] some stuff cutted here
return "index.php?".implode("&", $url);
}
In my template I use this
<a href="{buildURL params=$smarty.get bar="foo"}">foo</a>
this outputs for example:
index.php?a=5&b=7&c=9&bar=foo
If I don't want a variable in my url which appears in $smarty.get
if do this {buildURL param=$smarty.get a=null}.
The result of {buildURL param=$smarty.get a=""} would be
different. In this case a would be an empty string and not "nothing".
This is only one example (regardless of the usability of the above
function).
Another argument is (at least for me) that NULL is a common
expression in PHP as TRUE and FALSE are. So why allow TRUE
and FALSE but disallow NULL.
bye,
André
"Monte Ohrt" <monte@ispi.net> schrieb im Newsbeitrag
news:1045666432.28271.20.camel@lena.ispi.prv...
>
> As for null, example of what you want to do?
>
> On Wed, 2003-02-19 at 08:42, André Rabold wrote:
> > It was already discussed some time ago ... but I cannot find the thread
> > anymore and I cannot remember if a decission was made.
> >
> > I cannot use NULL as a function parameter in Smarty. But it would be
very
> > usefull for me to explicitly set some vars to NULL. For example if a
> > function has set a parameter to a default value other that "" or NULL.
> >
> > One other thing I discovered is the behaviour of TRUE and FALSE within a
> > template. Both get compiled as 1 or 0 not as true / false. It's nearly
the
> > same but not exacly.
> >
> > So I have created patch which "fixed" the TRUE/FALSE and adds support
for
> > NULL:
> >
> > Index: Smarty_Compiler.class.php
> > ===================================================================
> > RCS file: /repository/smarty/Smarty_Compiler.class.php,v
> > retrieving revision 1.177
> > diff -r1.177 Smarty_Compiler.class.php
> > 56c56
> > < var $_permitted_tokens =
> > array('true','false','yes','no','on','off');
> > ---
> > > var $_permitted_tokens =
> >
> > array('true','false','yes','no','on','off','null');
> > 664a665,666
> > > if (is_null($arg_value))
> > > $arg_value = 'null';
> > 1345c1347
> > < $token = true;
> > ---
> > > $token = 'true';
> > 1347c1349,1351
> > < $token = false;
> > ---
> > > $token = 'false';
> > > } else if ($token == 'null') {
> > > $token = 'null';
> >
> >
> >
> >
> > Good or bad?
> >
> > André
> --
> Monte Ohrt <monte@ispi.net>
>