Re: [SMARTY] Default variable values for forms

From: Date: Sun, 23 Jun 2002 20:21:14 +0000
Subject: Re: [SMARTY] Default variable values for forms
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-4979@lists.php.net to get a copy of this message
Hi, On Sat, Jun 22, 2002 at 03:25:34PM +0200, Lech Rychliñski wrote: > manual says that i can do sth like this: > > <input type="text" name="name" > value={$post.name|default:"&nbsp;"}> > > but in fact it doesn't change anything because I see error about name > index again. i've tried even sth like this: if you have error reporting set to E_ALL you might get some errors here and there, for example when using default. Below are the changes I had to do to Smarty_Compiler.class.php (from Smarty CVS as of this evening) to get default to work with error reporting set to E_ALL. The beginning of the patch, until the _run_mod_handler part is for some other problems I had because I have error reporting set to E_ALL. If you don't feel like using my ugly workaround you can always change your error reporting level to E_ALL & ~E_NOTICE (which is the default setting in PHP 4) and then default should work without any problems. Regards, Joakim --- Smarty_Compiler.class.php.org Sun Jun 23 22:54:07 2002 +++ Smarty_Compiler.class.php Sun Jun 23 23:18:47 2002 @@ -962,7 +962,7 @@ switch ($expr_type) { case 'even': - if (@$tokens[$expr_end] == 'by') { + if (isset($tokens[$expr_end]) && $tokens[$expr_end] == 'by') { $expr_end++; $expr_arg = $tokens[$expr_end++]; $expr = "!(($is_arg / $expr_arg) % $expr_arg)"; @@ -971,7 +971,7 @@ break; case 'odd': - if (@$tokens[$expr_end] == 'by') { + if (isset($tokens[$expr_end]) && $tokens[$expr_end] == 'by') { $expr_end++; $expr_arg = $tokens[$expr_end++]; $expr = "(($is_arg / $expr_arg) % $expr_arg)"; @@ -980,7 +980,7 @@ break; case 'div': - if (@$tokens[$expr_end] == 'by') { + if (isset($tokens[$expr_end]) && $tokens[$expr_end] == 'by') { $expr_end++; $expr_arg = $tokens[$expr_end++]; $expr = "!($is_arg % $expr_arg)"; @@ -1244,6 +1244,11 @@ else $modifier_args = ''; + // UGLY WORKAROUND BY ME + if ($modifier_name == 'default') + { + $output = "isset($output) ? $output : NULL"; + } $output = "\$this->_run_mod_handler('$modifier_name', $map_array, $output$modifier_args)"; } } -- Joakim Andersson ; tyrak@borgship.net ; http://borgship.net/~tyrak/

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