|
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 |
fbronx Smarty Rookie
Joined: 28 May 2003 Posts: 11 Location: Stekene, Belgium
|
Posted: Thu May 29, 2003 4:47 pm Post subject: {include} and compile_id |
|
|
I'm using template resources and the {include} statement for the themes of my CMS I'm currently developping. My question is: how can I use a compile_id for the templates that come from a resource? At the moment I have only one theme, but when I provide more there will be the danger that other theme templates get overwritten.
An example:
{capture name=content}
...
{/capture}
{include file="theme:main_block.tpl" title=#TITLE# content=$smarty.capture.content} |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu May 29, 2003 5:10 pm Post subject: |
|
|
you shouldn't bother if the template comes from a resource or from the filesystem. smarty uses different compiled templates for different compilde_ids in both cases. |
|
Back to top |
|
fbronx Smarty Rookie
Joined: 28 May 2003 Posts: 11 Location: Stekene, Belgium
|
Posted: Thu May 29, 2003 5:43 pm Post subject: |
|
|
Do you mean that the following code :
function theme_get_template ($tpl_name, &$tpl_source, &$smarty_obj)
{
global $g_settings;
$fname = dirname(__FILE__) . '/themes/' . $g_settings->style . '/templates/' . $tpl_name;
$fh = fopen($fname, 'r') or die("template $fname doesn't exist! ");
$tpl_source = fread($fh, filesize($fname));
fclose($fh);
return true;
}
doesn't create problems when $g_settings->style changes ? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu May 29, 2003 5:51 pm Post subject: |
|
|
you where talking about compile_ids. so if you have distinct compile_ids for each $g_sesstings->style it should work. |
|
Back to top |
|
fbronx Smarty Rookie
Joined: 28 May 2003 Posts: 11 Location: Stekene, Belgium
|
Posted: Thu May 29, 2003 6:35 pm Post subject: |
|
|
Ok. I just found out that I can set the compile_id after reading the template like this:
function theme_get_template ($tpl_name, &$tpl_source, &$smarty_obj)
{
global $g_settings;
$fname = dirname(__FILE__) . '/themes/' . $g_settings->style . '/templates/' . $tpl_name;
$fh = fopen($fname, 'r') or die("template $fname doesn't exist! ");
$tpl_source = fread($fh, filesize($fname));
$smarty_obj->compile_id = $g_settings->style;
fclose($fh);
return true;
}
I think this is a nice way of creating themes. Or are there better solutions for this? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu May 29, 2003 8:17 pm Post subject: |
|
|
id'd prefer simply assigning $theme and using {include file="$theme/foo.tpl"} everywhere instead of messing with resources and compile_ids |
|
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
|