Help understand Smarty - arrays, variables, general
| From: | Scott Phelps | Date: | Thu, 01 Jul 2004 19:02:54 +0000 |
| Subject: | Help understand Smarty - arrays, variables, general | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-11515@lists.php.net to get a copy of this message | ||
Please forgive me if I sound clueless here. I have been trying out
Smarty for three days now, and I have the following question:
If I have a PHP array in a separate include file that stores form data
like this:
---------------------------------------------
$formdata = array(
'name'=>$_POST['name'],
'company'=>$_POST['company'],
);
---------------------------------------------
And I want to copy this array to another form using the template syntax
like this:
---------------------------------------------
<p>Contact Name:
<input name='form2_name'
type='text' size='25' value={$name}></input></p>
....etc
---------------------------------------------
Then must I do this in my main .php file?
---------------------------------------------
$smarty->assign('WORKORDER',array(
"name"=>$name,
....etc
));
$smarty->display('index.tpl');
---------------------------------------------
This just seems soooo redundant. To assign form-data to one array, then
re-assign the array variables to the Smarty->array so the template can
see it!
I really don't get how Smarty is supposed to increase development time.
I seem to spend more time looking up how to do things the "Smarty" way,
and less time writing my real PHP code.
For example. In pure PHP I would code:
----------------------------
<?php
$var=$someClass->someMethod($ID);
?>
<html>
<?php print($var["valueName"]) ?>
</html>
----------------------------.
##### Now, Using Smarty ####
-------- index.php ---------
<?php
$var=$someClass->someMethod($ID);
$new_var=$var["valueName"];
$smarty->assign('var',$new_var);
?>
-------- index.tpl ---------
<html>
{$var}
</html
----------------------------
That just seems like a lot of extra steps just to hide PHP code from the
template.
Really, I am trying to find the advantages of why I should continue to
learn to use Smarty, and I would like to get some hints from you who use
it and have experience. Everyone says it makes them more productive so
maybe I am doing something _very_ wrong here. Please let me know!
{ I want to increase my productivity too :-) }
Thanks for the patience,
Scott Phelps