Multitheme support. How?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Aristona
Forum Commoner
Posts: 33
Joined: Thu Dec 02, 2010 8:14 am

Multitheme support. How?

Post by Aristona »

Hey,

I want to add a multitheme support to my CMS website, but I don't know how can I do it in a professional way.

My system differs PHP and HTML codes completely. For example:

test.php file

Code: Select all

LoadTemplate('test.tpl', array('MSG1' => 'Merhaba, 'MSG2' => 'Blahblah));
It's a bit more complicated but that's not important.

test.tpl file

Code: Select all

<h2><&MSG1></h2>
<h3><&MSG2></h3> 
MSG1 and MSG2 is being replaced by PHP.
Additionally, users can change their THEME path via configuration file.

config.php

Code: Select all

$config['THEME_PATH'] = 'theme/theme_1/';
 
THEME folder contains every theme. (Note that CSS's are not standart! It looks like a completely different website.)

My question is;

How can I add multitheme support in the most professional way?
For example, if I add theme_2, theme_3 and so on, I will have to define MSG3 if I ever add it on ALL theme files.
I am going to have 30+ theme support so it will be really complicated in the future.

How multitheme support can be handled professionally? I never used Wordpress and so on. How do they handle it?

Will be glad if you help,
Thanks.
incubi
Forum Contributor
Posts: 119
Joined: Mon Dec 07, 2009 1:47 pm

Re: Multitheme support. How?

Post by incubi »

One way to do this would be to store your theme template files in the database and call a them based on a Theme ID related to the theme the user picks. Then cookie that ID and when the page is loaded query for the theme. The issue with this is what if the page is called 10k times in a second, so some rate control would be needed. Probably not the best way but it is a way.

incubi
Aristona
Forum Commoner
Posts: 33
Joined: Thu Dec 02, 2010 8:14 am

Re: Multitheme support. How?

Post by Aristona »

incubi wrote:One way to do this would be to store your theme template files in the database and call a them based on a Theme ID related to the theme the user picks. Then cookie that ID and when the page is loaded query for the theme. The issue with this is what if the page is called 10k times in a second, so some rate control would be needed. Probably not the best way but it is a way.

incubi
Hi,

If I enter theme ID and theme template files into database and call them (definitely going to be some kind of caching there!) it would still require adding MSG3 variable to be written in.

For example;

THEME 1 - WELCOME.TPL

Code: Select all

<div align="center">
   <h3>
      <&MSG1> //contains "Welcome to my website dear, "
      <&USERNAME> //contains $_SESSION['username'];
    </h3>
</div>
THEME 2 - WELCOME.TPL

Code: Select all

<div id="container">
    <div id="content container" align="left">
        <p class="bdtext">
            <&MSG1> //contains "Welcome to my website dear, "
            <&USERNAME> //contains $_SESSION['username'];
        </p>
    </div>
</div>
Imagine I have 30 different themes and I want to make an addition like MSG3.

Code: Select all

<&MSG3> //contains "Not you? Please <a href="?logout">logout.</a> "
I would have open 30 different TPL files, write MSG3, save them... so much/unnecessary work I believe.
There should be some kind of easy logic behind it. :)
incubi
Forum Contributor
Posts: 119
Joined: Mon Dec 07, 2009 1:47 pm

Re: Multitheme support. How?

Post by incubi »

True, maybe there's a better way but I can't think of one at the moment. I can tell you that PHPrunner from (xlinesoft.com) uses placeholders for templates and that program is cool for non coder types :)
Aristona
Forum Commoner
Posts: 33
Joined: Thu Dec 02, 2010 8:14 am

Re: Multitheme support. How?

Post by Aristona »

Thanks. :)

I am still open for ideas though.
Post Reply