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

{include} and compile_id

 
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
fbronx
Smarty Rookie


Joined: 28 May 2003
Posts: 11
Location: Stekene, Belgium

PostPosted: Thu May 29, 2003 4:47 pm    Post subject: {include} and compile_id Reply with quote

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
View user's profile Send private message
messju
Administrator


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

PostPosted: Thu May 29, 2003 5:10 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
fbronx
Smarty Rookie


Joined: 28 May 2003
Posts: 11
Location: Stekene, Belgium

PostPosted: Thu May 29, 2003 5:43 pm    Post subject: Reply with quote

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
View user's profile Send private message
messju
Administrator


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

PostPosted: Thu May 29, 2003 5:51 pm    Post subject: Reply with quote

you where talking about compile_ids. so if you have distinct compile_ids for each $g_sesstings->style it should work.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
fbronx
Smarty Rookie


Joined: 28 May 2003
Posts: 11
Location: Stekene, Belgium

PostPosted: Thu May 29, 2003 6:35 pm    Post subject: Reply with quote

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
View user's profile Send private message
messju
Administrator


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

PostPosted: Thu May 29, 2003 8:17 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
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