Re: challenging Smarty - componentized template

Monte Ohrt <[email protected]>
Newsgroups gmane.comp.php.smarty.devel
Message-ID <[email protected]>
In short: include_php isn't typically necessary, use a custom function
instead. Example:

{load_ticker assign="ticker"}
Stock Name: {$ticker.name} Stock Price: {$ticker.price}

Here the load_ticker function goes to the work of fetching the ticker
info and assigning it to $ticker.

Using a custom function, you can just drop it into the plugin directory
and use it. {include_php ...} requires another place to contain your php
script and a little different method to put together. They essentially
perform the same operation in this case.

{include_php ...} isn't necessary unless you want to quarantine the
functionality to a "trusted" directory outside of the plugin directory.
I would recommend using custom functions whenever possible. I doubt
there is a significant performance difference between them, but I
haven't benchmarked it myself.

Monte

On Mon, 2004-02-16 at 16:44, Muhammed Mamedov wrote:
> ----- Original Message -----
> From: "Marcus Bointon" <[email protected]>
> To: "Smarty dev" <[email protected]>
> Sent: Monday, February 16, 2004 1:18 PM
> Subject: Re: [SMARTY-DEV] challenging Smarty - componentized template
> 
> 
> > on 14/2/04 22:23, Muhammed Mamedov at [email protected] wrote:
> >
> > > But still having some questions with the general Smarty work principle,
> like
> > > for example "Is there a performance difference using {include
> file='dddd.tpl'}
> > > and {include_php file=''somephp.file}?" I am currently trying `smartize`
> my
> > > 100% ready and running PHP site and wonder if I have to transform my
> .php
> > > includes into .tpl files where possible, or including php directly in
> > > templates is also ok..
> >
> > I don't know what the performance difference might be, because you
> probably
> > shouldn't be doing it anyway. Most of the point of Smarty is to keep code
> > out of your templates, or at least keep it to handling presentation logic
> > (which is what Smarty's logic is for), so you should not really ever need
> to
> > include a PHP file in your template.
> 
> m@m : You say that it is weird to include php files into templates. Well, I
> found this
> way to handle componentized templates from Smarty's Manual:( Chapter 18.
> Tips & Tricks,
> Componentized Templates). They even provide an example there :
> 
>  index.tpl
> ---------
> {* Smarty *}
> {include_php file="load_ticker.php"} {*  THIS IS THE WAY I DO MY
> PHP+TEMPLATE STUFF NOW *}
> Stock Name: {$ticker_name} Stock Price: {$ticker_price}
> 
> What do you think?..
> 
> 
> >
> > Including template components is an excellent way to work, I use it for
> > headers and footers etc. If you're regularly wanting to include PHP in
> your
> > templates, either you've got your logic mixed up, or you should perhaps
> look
> > at writing a Smarty extension...
> >
> 
> What is extension? Can you describe in brief? I will also check that
> myself..
> 
> > Marcus
> > --
> > Marcus Bointon
> > Synchromedia Limited: Putting you in the picture
> > [email protected] | http://www.synchromedia.co.uk
> >
> > --
> > Smarty Development Mailing List (http://smarty.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> >

-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.