Re: Basic question about passing variables

From: Date: Wed, 25 Apr 2001 21:55:36 +0000
Subject: Re: Basic question about passing variables
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-587@lists.php.net to get a copy of this message
Hi Luc, It looks like you have a class that generates HTML tables, as well as the content within the table. Normally you would want full control of your HTML layout handled by the template engine (Smarty). You would accomplish this by having your class return _only_ the data structure. You would then assign this data structure to the template, and then let the template generate the HTML tables that go around the data using {section}{/section} loops. However, if you want to leave your class as-is and just inject its output into the template, you can do this easily by creating a custom function that calls your class and returns the output. Monte Luc Saint-Elie wrote: > > 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 > > --- > You are currently subscribed to smarty as: monte@ispi.net > To unsubscribe send a blank email to $subst('Email.Unsub') > Visit Smarty's homepage at > http://www.phpinsider.com/php/code/Smarty/ -- Monte Ohrt <monte@ispi.net> http://www.ispi.net/

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