Re: Help understand Smarty - arrays, variables, general

From: Date: Fri, 02 Jul 2004 10:35:43 +0000
Subject: Re: Help understand Smarty - arrays, variables, general
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-11520@lists.php.net to get a copy of this message
Scott Phelps wrote:
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'], ); $smarty->assign('mydata',$formdata);
--------------------------------------------- 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 <input name="myname" type="text" value="{$mydata.name}">
also the post vars directly <input name="myname" type="text" value="{$smarty.post.name}">
--------------------------------------------- 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!
work great with a databasae ..eg Pear example $sql ="select id, name, address, email from members where name like'a%'"; $smarty->assign('members',$db->getAll($sql) );
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. http://smarty.php.net/whyuse.php
YOu need to have 2 heads - one as a pure php coder and one as the html/designer. That's the way I use it at work. the template/graphic designer does a mock up of the site/ forms etc I then build the database and the php logic. then the designer puts the finishing touches The main thing is that whatever the html designer does he ddoen'st touch or mess up the hp code and vice versa.. That's just the main advantage for me as well as all the modifiers, include files etc which make managing and maintaining a site so much easier.
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. that's the point ;-)
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! Good emaple recently - we wanted to add another link to the nav top n bot bar - I file change and site wide update DONE ! imagine dreamweaver templates !!!
{ I want to increase my productivity too :-) } eg todays data
Today is {$smarty.now|date_format:"d-m-y"}
Thanks for the patience, Scott Phelps
Its a bit of a learning curve I must admit, took me a while to "convert" my team but certainly there's no other way we'd do a site nowadays, exen simple 4 page ones! Keep at it. It'll be worth it , promise ;-) Pete big smarty fan

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