Re: Fully compile time includes
Martin Kjeldsen <[email protected]> Thu, 6 Oct 2005 08:22:19 +0200
| Newsgroups | gmane.comp.php.smarty.devel |
|---|---|
| Message-ID | <[email protected]> |
Antoher way of doing this is to use a compiler function. It used like this:
{compile_include template_name.tpl}
function sf_compile_include($file, &$smarty)
{
if ($file) {
$path = $smarty->_get_compile_path($file);
if ($smarty->_is_compiled($file, $path) || $smarty->_compile_resource($file, $path))
return '?>' . file_get_contents($path) . '<?php';
}
}
What it does is simply putting the template code directly into the parent template.
I've seen speedups when including the same template many time (like in a loop).
The downside is that any changes in the child template isn't detected in the parent, but
could be fixed.
I've used this for some time and it works.
Alain Williams (23:23 2005-10-05):
> On Wed, Oct 05, 2005 at 03:10:09PM -0700, boots wrote:
> > --- Alain Williams <[email protected]> wrote:
> > > What I want to achieve is that the contents of these small files are
> > > physically put into
> > > the compiled .php of the top level templates -- ie avoiding the extra
> > > work of opening the file.
> > > Perhaps some option to {include} might allow this or another verb
> > > like {include_static} or
> > > {include_paste} that just took the filename as an argument -- nothing
> > > else --
> > > might be another way.
> >
> >
> > Not an official solution but you may be interested in:
> > http://www.phpinsider.com/smarty-forum/viewtopic.php?t=5068
>
> Many thanks -- that is what I am looking for.
>
> Any idea how much speed improvement this gives ? OK I know that it will
> depend on all sorts of things.
>
> Any reason why something like this cannot be made 'official' ?
>
> I'm off to bed now, but will play with it later.
>
> Cheers
>
> --
> Alain Williams
> Parliament Hill Computers Ltd.
> Linux Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
> +44 (0) 787 668 0256 http://www.phcomp.co.uk/
>
> #include <std_disclaimer.h>
--
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php