|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
maka Smarty Rookie
Joined: 15 May 2003 Posts: 21 Location: Maringá-PR BRASIL
|
Posted: Wed Sep 17, 2003 9:14 pm Post subject: Nested cache |
|
|
// index.php
$body = $smarty->fetch('home.tpl');
$smarty->assign('body',$body);
$smarty->display('main.tpl',$cache_id);
// other_page.php
$body = $smarty->fetch('other_page.tpl');
$smarty->assign('body',$body);
$smarty->display('main.tpl',$cache_id);
and goes on for every pages.
The question is: If I need to update other_page.tpl, I NEED to update main.tpl too. There's other approch to never need update main.tpl?
A not "good" solution that I found is that:
$main = $smarty->fetch('main.tpl');
$body = $smarty->fetch('other_page.tpl');
$out = str_replace("@@BODY@@", $body, $main);
echo $out;
// where @@BODY@@ is other tag not smarty tags, that I use to replace with the body
But I don't really like this solution. Other solution would be using insert function and make the template stuffs inside the function ( what means the script parameter?? )
any IDEIA? perhaps using include ou include_php ? or maby using fetch in a PHP file that do the tamplate job?
|
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Sep 17, 2003 9:32 pm Post subject: |
|
|
why not use {include file="other_template.tpl"} from inside your main.tpl instead of doing everything manually? That way Smarty will figure out when and what needs to be compiled. |
|
Back to top |
|
maka Smarty Rookie
Joined: 15 May 2003 Posts: 21 Location: Maringá-PR BRASIL
|
Posted: Wed Sep 17, 2003 9:49 pm Post subject: |
|
|
but how can I do a test "is_cached()" for each file?
I mean...how can I have diferent cache_lifetime?
I make some test here and if compile_check is enable, any alteration in main.tpl or other_file.tpl makes both be updated |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Sep 18, 2003 2:58 am Post subject: |
|
|
Since you are only ever calling display on main.tpl, it looks like you need a different cache_id for each of main.php and other_template.php so that Smarty can create different cache files for each. Also, for the technique you are showing, you probably want to use the same cache_id during the fetch as you do for display. |
|
Back to top |
|
maka Smarty Rookie
Joined: 15 May 2003 Posts: 21 Location: Maringá-PR BRASIL
|
Posted: Thu Sep 18, 2003 6:22 pm Post subject: |
|
|
I'm not so good in English...so I'll try to express my self with 2 draws.
http://neves.bs2.com.br/smarty/2.gif
Above, is a link that show what almost peoples do. Separing the repetitive content in diferent included files...and load each one in his respective place. I think this approach more hard to mantain, since if I did just a simple alteration like change the meu from left to above the page, I'll need to update every template to acomodate the new layout
http://neves.bs2.com.br/smarty/1.gif
Here is a img that show What I want to do. Having a content that is independent of where it's going to be placed. But has a problem that if I need to include something at the head!!
What solution do YOU use? or think is better? And about using only one php file? is it a good technique?
thanks |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Sep 18, 2003 6:38 pm Post subject: |
|
|
I prefer the 2nd demonstration that you made. I think something like this is what you are after:
index.php
$content_source = 'home';
$smarty->assign('content_template', $content_source . '.tpl');
$smarty->display('main.tpl', $content_source);
page1.php
$content_source = 'page1';
$smarty->assign('content_template', $content_source . '.tpl');
$smarty->display('main.tpl', $content_source);
main.tpl
{include file=header.tpl}
{include file=$content_template}
{include file=footer.tpl} |
|
Back to top |
|
|
|
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
|