how to treat different index / templates for the same site?

3

I have 10 distinct html / php templates and via panel (admin) the client can select one of the 10 templates for his site.

My question is how to get the website to know which template to open. In the panel I save the selected template in the database.

In the site how do I, for example, open the index of template09 or the index of template02 being everything in separate folders?

ex. templeate01 / index, template02 / index ....

Without it appearing in the url the redirection (fulano.com.br/template09).

Can I handle htaccess with php? Any tips or examples?

    
asked by anonymous 18.01.2015 / 20:11

3 answers

2

For this problem there are tens / hundreds maybe even thousands of possible solutions. I'll post a structure I used.

Structure

\
|__ Templates\
|   |__ Default\
|   |   |__ css\
|   |   |__ js\
|   |   |__ img\
|   |   |__ index.php
|   |
|   |__ Dark\
|   |   |__ css\
|   |   |__ js\
|   |   |__ img\
|   |   |__ index.php
|   |
|   |__ Light\
|       |__ css\
|       |__ js\
|       |__ img\
|       |__ index.php
|
|__ Pages\
|   |__ home.php
|   |__ contato.php
|   |__ sobre.php
|   |__ 404.php
|
|__ index.php /* Código do arquivo abaixo */
|__ menu.php

index.php

define('TITULO', 'Site com vários templates');
$page = (!empty($_GET['page']) $_GET['page'] : 'home';

if (file_exists(__DIR__.'\pages\'.$page.'php'))
   define('PAGE' file_exists(__DIR__.'\pages\'.$page.'php'));
else
   define('PAGE', __DIR__.'\pages\404.php');

define('MENU', __DIR__.'\menu.php');

// Este valor pode ser recebido do  banco de dados, ou de algum arquivo de configuração
$template = "Default";

require_once __DIR__.'\Templates\'.$template.'\index.php';

Templates files

In each file index.php of each template you should have your HTML code and files like CSS and Javascript should be referenced with absolute path, for example:

<!DOCTYPE html>
<html>
<head>
    <title><?=TITULO?></title>
    <link rel="stylesheet" type="text/css" href="http://meudominio.com/Templates/Default/estilos.css">
<script src="http://meudominio.com/Templates/Default/arquivo.js"></script>
</head>
<body>
    <?php
        require_once MENU;            
        require_once PAGE;
    ?>
</body>
</html>
    
19.06.2015 / 03:41
1

What I do is a search in the database and I get the theme that the user is using and I do this:

switch ($retornoBanco) {
    case 0:
        include="tema1.php";
        break;
    case 1:
        include="tema2.php";
        break;
    case 2:
        include="tema3.php";
        break;
    default:
        include="temaDefault.php";
        break;

Then you do this dynamically and add the page inside the main index.

    
19.05.2015 / 18:35
0

Just so that the response has the deserved visibility, I will refuel the solution now given in comment.

If I understood correctly, at the time of the include / require, you query the value stored in the database, read the obtained resource, and use the value stored as part of the path / p>

Simple and right ^ _ ^

    
19.01.2015 / 10:12