View previous topic :: View next topic |
Author |
Message |
iriePub Smarty Regular
Joined: 16 Jun 2006 Posts: 53
|
Posted: Thu Aug 17, 2006 12:49 pm Post subject: Fetch vs. Display() |
|
|
Hi,
What is better to use concerning the performance?
I like {include} much more to keep the templates simple and readable, then to fetch in php and assign to smarty, because when using only one time display(), you can assign all neede vars to smarty and use them in your templates ...
But is this slower than fetching the results of templates and assigning them to smarty?
Thanks in advance! |
|
Back to top |
|
spunkymungbeans Smarty Regular
Joined: 14 Mar 2005 Posts: 49
|
Posted: Sun Aug 20, 2006 5:08 am Post subject: |
|
|
The only time I use fetch() is when I need some html to use later in the program. For example I might use smarty to create the contents for an email and then use fetch to assign it to a variable which is then plugged into the sendmail function. Or if I am going to have the content saved to a file rather than displayed.
I can't see any advantage in using it instead of {include}.
If you mean the fetch function such as this:
Code: |
{* include some javascript in your template *}
{fetch file="/export/httpd/www.example.com/docs/navbar.js"}
|
then surely this would only be useful to include files that do not contain any variables.
Perhaps I'm misunderstanding the question. _________________ Leonie |
|
Back to top |
|
iriePub Smarty Regular
Joined: 16 Jun 2006 Posts: 53
|
Posted: Sun Aug 20, 2006 11:01 am Post subject: |
|
|
No, I mea the first thing., using $smarty->fetch() in your php code instead of {include} in the template tag, to contrcut a deeper nesting of templates! |
|
Back to top |
|
mateusfig Smarty Rookie
Joined: 27 Aug 2006 Posts: 24
|
Posted: Tue Sep 05, 2006 5:31 pm Post subject: |
|
|
iriePub wrote: | No, I mea the first thing., using $smarty->fetch() in your php code instead of {include} in the template tag, to contrcut a deeper nesting of templates! |
I think i understood what u meant. I thought on same subject today. But i use FETCH function w/ HTML only.
I needed use FETCH because i use separated folders modules in my system and i need process them before include them into "father" template of website.
The "father" template receives the code of each module which it needs and placed in the right place of code. This would not be possibly without process each module into a separated variable that will store each one.
________
Ferrari Testarossa Specifications
Last edited by mateusfig on Sun Feb 13, 2011 2:57 am; edited 1 time in total |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Sep 05, 2006 6:13 pm Post subject: |
|
|
$smarty->fetch() is going to accumulate the output of the templates into system memory. Generally it is better to avoid that if you have no good purpose of fetching content. |
|
Back to top |
|
mateusfig Smarty Rookie
Joined: 27 Aug 2006 Posts: 24
|
Posted: Tue Sep 05, 2006 6:37 pm Post subject: |
|
|
mohrt wrote: | $smarty->fetch() is going to accumulate the output of the templates into system memory. Generally it is better to avoid that if you have no good purpose of fetching content. |
Alright, good to know about this. But do i have a alternative? like clean this content from memory after i use it?
I'd like find a better way to build my idea since it seems is not a professional act what I'm using actually.
is there any fucntion to free the memory after shows the content?
________
Mazdago
Last edited by mateusfig on Sun Feb 13, 2011 2:58 am; edited 1 time in total |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Sep 05, 2006 7:48 pm Post subject: |
|
|
If you do this:
[php:1:82a61116be]$output = $smarty->fetch('foo.tpl');[/php:1:82a61116be]
the variable $output resides in memory, until you either unset() it or the script terminates. If you do this:
[php:1:82a61116be]$smarty->display('foo.tpl');[/php:1:82a61116be]
The output goes straight to the browser.
If $smarty->fetch() works for you, then there should be no problem using it. I'm just pointing out the difference between fetch() and display(). Run some benchmarks, see if there is any significant difference for you. |
|
Back to top |
|
mateusfig Smarty Rookie
Joined: 27 Aug 2006 Posts: 24
|
Posted: Tue Sep 05, 2006 8:09 pm Post subject: |
|
|
mohrt wrote: | If you do this:
[php]$output = $smarty->fetch('foo.tpl');[/php]
the variable $output resides in memory, until you either unset() it or the script terminates. If you do this:
[php]$smarty->display('foo.tpl');[/php]
The output goes straight to the browser.
If $smarty->fetch() works for you, then there should be no problem using it. I'm just pointing out the difference between fetch() and display(). Run some benchmarks, see if there is any significant difference for you. |
Thats all. Great information, u recalled me about the unset() function which can make this in case i need this...
Thank u very much.
________
Starcraft replays |
|
Back to top |
|
|