Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Using multiple $smarty->display() instead of tag {insert}

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
atpower
Smarty Rookie


Joined: 23 Jul 2003
Posts: 6

PostPosted: Tue Aug 05, 2003 5:07 am    Post subject: Using multiple $smarty->display() instead of tag {insert} Reply with quote

first,let me show you the files.

index.php
[php:1:1ec9644a21]
<?php
include_once ('Smarty/Smarty.class.php');
$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->caching = true;
$smarty->display('head.tpl.html');
echo 'I am the content.'; //you can change this with the caching turned on
$smarty->display('foot.tpl.html');
?>
[/php:1:1ec9644a21]

head.tpl.html
Code:
I am the header.


foot.tpl.html
Code:
I am the footer.


The caching is turned on,but if you change the message 'I am the content.',it will change immediately in the IE.how do you think about this method?

I don't like using the tag {insert} because its way to solve the dynamic caching problem,it returns the result of the function,I think its not powerful enough.But in the manual ,it says that the tag {insert} can be worked for things like poll ,user feedback areas,etc.I don't know how to make it .Can any body show me a simple example?
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Aug 05, 2003 9:37 am    Post subject: Reply with quote

if your biggest problem is, that insert has to *return* the output and not *echo* it: use output-buffering. ( http://php.net/manual/en/ref.outcontrol.php ) . it's damn easy and very powerful.

[php:1:9f1722c819]
function insert_foo($params, &$smarty) {
ob_start();
// output all stuff you want to be display not cached here
// do echo or print() or file() etc.. even include() or $smarty->display()
...
$ret = ob_get_contents();
ob_end_clean();
return $ret;
}[/php:1:9f1722c819]
Back to top
View user's profile Send private message Send e-mail Visit poster's website
atpower
Smarty Rookie


Joined: 23 Jul 2003
Posts: 6

PostPosted: Tue Aug 05, 2003 11:53 am    Post subject: Reply with quote

well done,that's a good idea,I haven't thougt it before.
but I have heared somebody say that using the tag {insert} will be very slow,is that really?

BTW:
[php:1:ea24fc080b]<?php
function insert_foo($params, &$smarty) {
ob_start();
// output all stuff you want to be display not cached here
// do echo or print() or file() etc.. even include() or $smarty->display()
...
$ret = ob_get_contents();
ob_end_clean();
return $ret;
}
?>[/php:1:ea24fc080b]

Is this the way you solve the problem,I mean to keep some area varible when caching turned on. Wink
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Aug 05, 2003 12:21 pm    Post subject: Reply with quote

atpower wrote:
have heared somebody say that using the tag {insert} will be very slow,is that really?


as so often: it depends. a cached page with an insert will always be slower than a cached page without inserts. also: the parameters that are passed to the insert function are cached, that means they are unserialized at each display. this can become slow if you have a lot of params that you pass to your insert-functions.

Quote:
BTW:
[...code...]

Is this the way you solve the problem,I mean to keep some area varible when caching turned on. Wink

Smile yep i did it that way in a project and it worked fine for me.

the next version of smarty will allow a slightly different approach to solve this: you can register plugins whose output won't be cached. i hope this will be a bit more flexible and also faster than insert-functions, but i didn't compare the performance of the two yet. you can checkout the cvs-version of smarty if you want to play with this. the more people who test it the sooner it will get stable and be released. Wink
Back to top
View user's profile Send private message Send e-mail Visit poster's website
atpower
Smarty Rookie


Joined: 23 Jul 2003
Posts: 6

PostPosted: Tue Aug 05, 2003 4:09 pm    Post subject: Reply with quote

Thank you Very Happy . Wish next version of Smarty can bring us excellent solution to this weak pot.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP