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

Asked

Viewed 235 times

3

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

My question is how to make the site know which template to open. In the panel I save the selected template at the base.

On the website how do I, for example, open the template09 index or template02 index and everything is in separate folders?

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

No redirection to appear in the url (fulano.com.br/template09).

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

  • If I understood correctly, at include time, you consult the bank, read the resource and use the stored value as part of the path inclusion.

  • That’s right, simple as that...

3 answers

2

For this problem has tens/ hundreds maybe even thousands of possible solutions. I will post a structure that 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 must have your HTML code and files like CSS and Javascript must be re-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>

1

What I do is I search the database and I take what theme 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;

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

0

Just so that the answer has the visibility deserved, I will reset the solution given in comment.

If I understand correctly, when doing include/require, you query the value stored in the database, read the resource obtained and use the stored value as part of the path inclusion.

Simple and right ^_^

  • 1

    From what I understand, the OP does not know how to do this...

  • I abstained from putting a pseudo-code because of his reply just above. If necessary, I complement.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.