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

Themeing - best practices ?
Goto page 1, 2  Next
 
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 -> Tips and Tricks
View previous topic :: View next topic  
Author Message
eadz
Smarty Regular


Joined: 30 Apr 2003
Posts: 61
Location: Auckland, New Zealand

PostPosted: Tue May 27, 2003 10:46 pm    Post subject: Themeing - best practices ? Reply with quote

Hi there,
Im developing a program that has themes using smarty remplates. The "theme" is defined in the database, and changable dynamicly.

I.e. I have a templates directory

/templates/green
/template/brown

and also an admin template section for the admin interface
/templates/admin

I'm having trouble working out how to do this. My first idea was to have a "compiled" directory inside the theme directory :

template/*theme*/compiled

The problem with this is when you have 20 themes, that's a lot of chmod 777 ing, So i really want only one compiled directory.
Also, I have a wrapper class that extends the Smarty class, and I tried to do some fancy things inside the display function, but when you "include file=blah" inside a template, smarty uses it's own fetch/display code so that didn't work.

What's the best way to do this?
_________________
bBlog - Smarty based blogging software
I work for Webforce web site design ( Auckland, NZ )
Back to top
View user's profile Send private message Visit poster's website
AZTEK
Smarty Pro


Joined: 16 Apr 2003
Posts: 235
Location: Purdue University

PostPosted: Wed May 28, 2003 1:39 am    Post subject: Reply with quote

i have it so each template has its wrapper class like theme_brown extends Smarty then modified the template_dir and such to a themes/themename/templates and so on so each theme remains seperate.
_________________
"Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane
Back to top
View user's profile Send private message Visit poster's website
eadz
Smarty Regular


Joined: 30 Apr 2003
Posts: 61
Location: Auckland, New Zealand

PostPosted: Wed May 28, 2003 1:45 am    Post subject: Reply with quote

AZTEK wrote:
i have it so each template has its wrapper class like theme_brown extends Smarty then modified the template_dir and such to a themes/themename/templates and so on so each theme remains seperate.


Ok.. that sounds wacky. I already have a class that extends smarty and I don't want another one..
_________________
bBlog - Smarty based blogging software
I work for Webforce web site design ( Auckland, NZ )
Back to top
View user's profile Send private message Visit poster's website
sweatje
Smarty Regular


Joined: 17 Apr 2003
Posts: 70
Location: Bettendorf, Iowa, USA

PostPosted: Wed May 28, 2003 2:04 am    Post subject: Reply with quote

Then how about adding a parameter you pass to your extension class for the theme.
_________________
Jason
jsweat_php AT yahoo DOT com
Back to top
View user's profile Send private message
eadz
Smarty Regular


Joined: 30 Apr 2003
Posts: 61
Location: Auckland, New Zealand

PostPosted: Wed May 28, 2003 2:18 am    Post subject: Reply with quote

sweatje wrote:
Then how about adding a parameter you pass to your extension class for the theme.


I tried that. In my extention class I had :

function display($page) {
// some code
parent::display(THEME."/".$page);

and that worked, but in the template file {include file="header.html"} etc didnt work because it should have been {include file="theme/header.html},and as it's in the same directory, it really should be just header.html.

How would I go about using a compile id in this situation? would it help?
_________________
bBlog - Smarty based blogging software
I work for Webforce web site design ( Auckland, NZ )
Back to top
View user's profile Send private message Visit poster's website
sweatje
Smarty Regular


Joined: 17 Apr 2003
Posts: 70
Location: Bettendorf, Iowa, USA

PostPosted: Wed May 28, 2003 2:55 am    Post subject: Reply with quote

It sounded like AZTEK's idea was the best...have a themes/NAME/templates directory, and set that directory _AS_ the template directory. All same directory includes should work fine.

Alternativly, you could do all your theming in style sheets and just to
Code:
<link  rel="stylesheet" href="{$theme_name}.css" type="text/css" />
after all, that is what CSS is for Wink
_________________
Jason
jsweat_php AT yahoo DOT com
Back to top
View user's profile Send private message
eadz
Smarty Regular


Joined: 30 Apr 2003
Posts: 61
Location: Auckland, New Zealand

PostPosted: Wed May 28, 2003 3:17 am    Post subject: Reply with quote

sweatje wrote:
It sounded like AZTEK's idea was the best...have a themes/NAME/templates directory, and set that directory _AS_ the template directory. All same directory includes should work fine.


That would be ideal, but for the compile directory.

Becasue the files have the same names, they would get mixed up when they are compiled becasue "home.html" is saved under the compile directory as "home.html" no matter what theme it came from.
_________________
bBlog - Smarty based blogging software
I work for Webforce web site design ( Auckland, NZ )
Back to top
View user's profile Send private message Visit poster's website
sweatje
Smarty Regular


Joined: 17 Apr 2003
Posts: 70
Location: Bettendorf, Iowa, USA

PostPosted: Wed May 28, 2003 4:28 am    Post subject: Reply with quote

Make a separate compile directory per theme, or use the theme name as a compile id.
_________________
Jason
jsweat_php AT yahoo DOT com
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed May 28, 2003 5:03 am    Post subject: Reply with quote

eadz wrote:
sweatje wrote:
It sounded like AZTEK's idea was the best...have a themes/NAME/templates directory, and set that directory _AS_ the template directory. All same directory includes should work fine.


That would be ideal, but for the compile directory.

Becasue the files have the same names, they would get mixed up when they are compiled becasue "home.html" is saved under the compile directory as "home.html" no matter what theme it came from.


As long as your file has a unique path under the template_dir, the file names will not collide. So:

templates/THEME1/home.tpl
templates/THEME2/home.tpl

will not have any collision problem, they have unique paths.

The only time you need to mess with compile id is if you want different compiled files for the same templates, such as different languages.

Monte
Back to top
View user's profile Send private message Visit poster's website
eadz
Smarty Regular


Joined: 30 Apr 2003
Posts: 61
Location: Auckland, New Zealand

PostPosted: Wed May 28, 2003 8:38 am    Post subject: Reply with quote

sweatje wrote:
Make a separate compile directory per theme, or use the theme name as a compile id.


Right. In my original post I said that I had already used seperate compile directories. And I think that is the 2nd best solution. The only drawback is that you have to chmod 777 all the compiled directories, which when you have a lot of themes can be a pain.

I have hope for the compile id, I read the manual page about the compile id, but I missed the one on the display() function.

SO..
I think the trick is to do it like this :

compiled_templates/
templates/green/index.html
templates/blue/index.html

[php:1:6c736a09e2]
$theme = 'blue';

$Smarty->template_dir = "templates/".$theme;
$Smarty->compile_dir = "compiled_templates";
$Smarty->compile_id = $theme;
$Smarty->display("index.html");
[/php:1:6c736a09e2]

Thanks for the help people Smile
_________________
bBlog - Smarty based blogging software
I work for Webforce web site design ( Auckland, NZ )
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed May 28, 2003 1:42 pm    Post subject: Reply with quote

It would be easier to not mess with compile_id and use only one compile_dir and template_dir. Something like this:

templates_c
templates/green/index.html
templates/blue/index.html

[php:1:ea89b0ff66]
$theme = 'blue';

$smarty->compile_dir = 'templates_c';
$smarty->template_dir = 'templates';
$smarty->display("$theme/index.html");
[/php:1:ea89b0ff66]
Back to top
View user's profile Send private message Visit poster's website
eadz
Smarty Regular


Joined: 30 Apr 2003
Posts: 61
Location: Auckland, New Zealand

PostPosted: Wed May 28, 2003 7:23 pm    Post subject: Reply with quote

mohrt wrote:
It would be easier to not mess with compile_id and use only one compile_dir and template_dir. Something like this:

templates_c
templates/green/index.html
templates/blue/index.html

[php:1:e62dbf8efc]
$theme = 'blue';

$smarty->compile_dir = 'templates_c';
$smarty->template_dir = 'templates';
$smarty->display("$theme/index.html");
[/php:1:e62dbf8efc]


But then {include file="header.html"} has to become {include file="$theme/header.html"} - Which doesn't make sence from a templateing point of view. The file paramater of include is supposed to be a relitive or absolute path but it's neither in this case.
_________________
bBlog - Smarty based blogging software
I work for Webforce web site design ( Auckland, NZ )
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed May 28, 2003 7:30 pm    Post subject: Reply with quote

Why does that not make sense? It doesn't make sense to me to change template directories based on theme, then have to mess with compile_id as a consequence. You are only adding a layer of complexity that isn't needed and also limiting flexability. With $theme used in the templates, you can switch between different themes with minimal intervention from the application.

Monte
Back to top
View user's profile Send private message Visit poster's website
eadz
Smarty Regular


Joined: 30 Apr 2003
Posts: 61
Location: Auckland, New Zealand

PostPosted: Wed May 28, 2003 7:50 pm    Post subject: Reply with quote

mohrt wrote:
Why does that not make sense? It doesn't make sense to me to change template directories based on theme, then have to mess with compile_id as a consequence. You are only adding a layer of complexity that isn't needed and also limiting flexability. Monte


From a designer point of view :

if you have a
/templates/blue/main.html
/templates/blue/contact.html
/templates/blue/inc/header.html
/templates/blue/inc/footer.html

Then the logical thing to include the header file from main.html would be {include file="inc/header.html"}.

I havn't needed a compile id before, but IMHO I think this is a perfect use. If it's not supposed to be used in this situation, what situaltion is it supposed to be used in.

Quote:
With $theme used in the templates, you can switch between different themes with minimal intervention from the application.


I want to be able to switch themes with minimal intervention from the user.
_________________
bBlog - Smarty based blogging software
I work for Webforce web site design ( Auckland, NZ )
Back to top
View user's profile Send private message Visit poster's website
fbronx
Smarty Rookie


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

PostPosted: Wed May 28, 2003 8:21 pm    Post subject: Theme resource Reply with quote

I use themes also for my CMS I'm working on and I've got the following problem:

Themes can be applied for several blocks on the page. That's why I always use {capture} and pass the content of the capture to an {include} of a theme template.

Looks like this:

{capture name=content}
...
{/capture}
{include file='theme:main_block.tpl' title=#TITLE# content=$smarty.capture.content}

The theme_get_template function makes sure that the right template is loaded. Themes are placed in separate directories.

Now how can I be sure that two different themes don't overwrite the templates in the templates_c directory? I don't feel like to create a templates_c directory for each theme.
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 -> Tips and Tricks All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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