Re: Other directories and Smarty
| From: | Monte Ohrt | Date: | Thu, 22 Feb 2001 15:11:18 +0000 |
| Subject: | Re: Other directories and Smarty | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-191@lists.php.net to get a copy of this message | ||
Hi Adrian,
I've done a bit of brainstorming on this issue. If I missed anything or
misunderstood what your needs are, let me know :-) First of all, lets
look at a method of doing this with no modifications to Smarty:
An overview of how Smarty works:
* Smarty traverses the entire template directory
* If any templates need compiling, Smarty compiles them and puts
the results into the templates_c directory with the same
directory structure.
* Smarty executes the application
If we try to add new template directories to Smarty, then Smarty must
figure out what needs to be compiled and where to put them all without
conflicts. Remember there is only one directory that compiled templates
are placed, we don't want to introduce name-space conflicts.
We can devise a method to manage our directory structures in a way that
Smarty understands, using symbolic links.
For example, let's say we have applications that all share common
templates. What you would want to do is put your common templates in a
directory by themselves.
common templates
----------------
/export/smarty/templates/common/
/export/smarty/templates/common/header.tpl
/export/smarty/templates/common/footer.tpl
application templates
---------------------
/export/httpd/www.mysite.com/templates/
So we have our template directory, but we want to be able to access our
common templates as well. We accomplish this by symlinking the common
template directory into our application template directory.
/export/httpd/www.mysite.com/templates/common ->
/export/smarty/templates/common/
This way, Smarty "sees" the common templates as a subdirectory in the
application template directory, and can then traverse and compile the
common templates without interference with the application templates.
Now in your application template, include the common templates like so:
{include file="common/header.tpl"}
This also makes things clear in your template which includes are
application templates, and which are common templates. If you have more
than one source of common templates, add more symlinks.
And now, another idea:
method that involves changing smarty
------------------------------------
We could change Smarty so that the $template_dir can take an associative
array of values, like so:
$template_dir = array("/path/to/common/templates/" => "common",
"/path/to/application/templates/" => "app");
Then to include templates, you must include them like so:
{include file="common/header.tpl"}
{include file="app/body.tpl"}
Smarty would then traverse all templates in every directory to compile
them, and all templates would be in a subdirectory of the template
directory, and must be called as such from the template. At first glance
this looks doable, but may not be an easy change :-)
other ideas?
Monte
Adrian Teasdale wrote:
>
> Hi everyone :)
>
> I saw a message on here about including templates from other directories and
> I was wondering if there is a solution yet as we are running into the same
> problem.
> This is our problem:
>
> 1. Within out applications we need to have quite a few template directories.
> This is so that we can share common templates with other templates
>
> 2. I would like to be able to share these tempaltes, via an include
> statement, but it will not work as I cannot point Smarty to use another
> template dir
>
> We do have a workaround at the moment, but this is what it is - a
> workaround - and I would like to see if something can be added into Smarty
> to help with this.
> Our current workaround is to include the compiled template via embedded PHP
> code, which is not good. For example:
>
> {literal}<?php include '../shared_templates/template.tpl.php' ?>{/literal}
> Any help would be GREATLY appreciated
>
> All the best to everyone. Smarty is excellent!
>
> Ade
>
> --- i n o v i c a . c o m ------------------------
> e: inspireme@inovica.com
> w: http://www.inovica.com
>
> Web Apps, virtual communities and vertical portals
> Hosting and dedicated servers just around the corner
> Contact us for low-cost domain name registration
> ----------------------------------------------------
>
> ---
> You are currently subscribed to smarty as: monte@ispi.net
> To unsubscribe send a blank email to $subst('Email.Unsub')
> Visit Smarty's homepage at
> http://www.phpinsider.com/php/code/Smarty/
--
Monte Ohrt <monte@ispi.net>
http://www.ispi.net/