Basic question about passing variables
| From: | Luc Saint-Elie | Date: | Wed, 25 Apr 2001 21:39:12 +0000 |
| Subject: | Basic question about passing variables | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-586@lists.php.net to get a copy of this message | ||
hello,
I'm discovering Smarty so excuse in advance the somehow naive aspect of my question
Right now I have cut my site (a portal kind of site) in templates files more or less each one representing a bloc (a table in fact)
I have two basic questions :
1) I'm not clear about how to insert a function, (a Class in fact) in a template.
For example I've a class that fetch a product reference in a database and display a Table with the product picture, price and description on a random basis, each time the user reload the page, the product changes.
In my conventional site I do :
//-----------------
$pubobject = new RandomAdd();
echo $pubobject->CreateTable('140');
//------------------
I learn in the doc that it is not advised to use php code in a template file.
How can I do this ?
2) Somehow the same question but with a switch() (or the template script language equivalent
my index.php file calls a index.tpl template that calls a whole bunch of templates files
I would like to do in index.tpl the equivalent of the classical
switch($op){
case 'news' : include (news.tpl');
break;
case 'article' : include ('article.tpl);
break;
default......
[....]
}
the intended result is
http://www.mysite.com/index.php => include no file
http://www.mysite.com/index.php?op=article => => include file article.tpl
http://www.mysite.com/index.php? => include file news.tpl etc...
I tried the following that doesn't work :
{if $op == "article"}
{include file="article.tpl"}
{else}
{include file="corps.tpl"}
{/if}
Quick start tutorial states :
"You can pass as many variables as you want. The included file inherits all the current template vars plus any that are passed to it"
What is the right way ?
Thanks in advance
Luc