Re[3]: [SMARTY] dyamic include file variable
| From: | Bertrand DUNOGIER | Date: | Thu, 09 Jan 2003 18:57:24 +0000 |
| Subject: | Re[3]: [SMARTY] dyamic include file variable | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7091@lists.php.net to get a copy of this message | ||
smc> I agree with the personal preference issue. I do not find the
smc> look of a URL with parameters unpleasant, and I do find comfort
smc> in knowing where all of the application flow is going.
I'm gonna quickly describe a method i have used on 2 sites so far, and
that seems to be good with Smarty.
First, it requires the usage of mod_rewrite, so it is not to be used
in every situation.
I'll quickly explain de files structure since even if it's half off
topic, it's part of the situation:
/site_root/
/html/
/templates/
/phpdata/
/smarty_config_files/
/functions/
... (other PHP stuff, we don't care here)
/httpd_data/
/smarty_templates_c/
/smarty_cache/
All the URL are classic links, e.g. site.com/dir/page.php
I have a set of rewrite rules who rewrite any link as follows:
http://www.site.com/dir/page.php?foo=bar
=>
http://www.site.com/handler.php?p=dir/page.php&foo=bar
I also have an auto_append and auto_prepend files who take care about
the path, DB connection and any TOTALLY general stuff.
In handler, the $_GET['p'] param is analyzed and two variables are
set: $template and $script. Stuff related to this section is processed
in this file (news grabbing, permissions check, and so on).
If $script & $template does not exist, a 404 page is displayed. If
$script exists, it is included. If $template exists, it is displayed.
/html/ and /templates contain the same directory and files structure.
It just occurs that some script do not need a template (redirection)
or do not need a script ("static" page).
For the templates structure, i use a main.tpl file, which contains a
{include file=$template} line. $template is set from handler.php.
When the site / app contains several sections (by instance admin and
client sections), a different handler is used, (e.g.
/admin/handler.php) with different templates_path and compile_dir.
This way, the links look good, the web statistics are relevant, and
the structure is easily managed.
It's probably not the best method, but I think it's a good one :)
Bertrand / Katana