View previous topic :: View next topic |
Author |
Message |
sviver Smarty Rookie
Joined: 14 Jun 2006 Posts: 6
|
Posted: Wed Jun 14, 2006 8:39 pm Post subject: compile method |
|
|
Hello,
Maybe I'm just too tired to think, but am I right that there is no simple method for compiling a temlate in Smarty.class.php?
Sometimes it would be nice to only compile a template, without then "running" it, so that in the production enviroment there is a compiled version of every template. (And templates_c would not have to be writeable.) I am thinking of a function as simple as display(), where you don't have to worry about compiled template filenames etc.
(Calling fetch() is not an option, as the tpl may use object variables, in which cause you get an error, because the reference is null.)
This could be solved by introducing a new parameter "$compileonly" for the fetch() method, and placing some ifs in the method body. (At least two: where the compiled template is included.) Then create a new compile) method, similar to display().
I have done this and it seems to work - although I did not test every aspect of it. The method could return true or false depending on the success of compilation.
If I am not the only one who finds this functionality useful, maybe it could be included in the standard version. If any help is needed, let me know.
Have a nice day,
Oliver |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
|
Back to top |
|
TGKnIght Smarty Junkie
Joined: 07 Sep 2005 Posts: 580 Location: Philadelphia, PA
|
Posted: Thu Jun 15, 2006 1:09 am Post subject: |
|
|
Are you trying to find a way to have everything compiled before someone actually calls your PHP file?
I think you could possibly write a script to crawl your website and force Smarty to do it's work before hand?
Which step are you trying to skip here?
- Template designer writes template in Smarty syntax.
- PHP Coder uses $smarty->display() on said .tpl file.
- If cache already exists, Smarty outputs the cached HTML, Else if compile already exists Smarty runs the compiled PHP version, Otherwise Smarty parses and compiles the designer's template into PHP, and optionally caches resulting HTML as well..
_________________ Smarty site with one index.php controller file
Working with MySQL and Smarty
SmartyColumnSort
Custom Smarty Javascript Debug Template |
|
Back to top |
|
sviver Smarty Rookie
Joined: 14 Jun 2006 Posts: 6
|
Posted: Sun Jun 18, 2006 9:00 pm Post subject: |
|
|
Hello boots
Not exactly I think. What I want to do is to precompile .tpl files from the templates dir, so that they get saved into templates_c. Just as they would during the first display() call. The point is however, that this can be done by say the PHP developer, after development has finished. After this templates_c can be set read-only, and also compile_check can be turned off. |
|
Back to top |
|
sviver Smarty Rookie
Joined: 14 Jun 2006 Posts: 6
|
Posted: Sun Jun 18, 2006 9:04 pm Post subject: |
|
|
Hi TGKnIght,
TGKnIght wrote: | Are you trying to find a way to have everything compiled before someone actually calls your PHP file?
I think you could possibly write a script to crawl your website and force Smarty to do it's work before hand?
|
Yes, that's what I want to do: write a script which compiles every tpl in advance. However, IMHO currently I can only:
1) Use methods of Smarty_Compiler - in this case you have to take care of assigning several parameters.
2) Use display() or fetch(). This is rather easy, but it does not only compile the .tpl, it also includes it. You could of course throw away output, but the problem is that without proper test input it might not run.
[/list] |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
|
Back to top |
|
sviver Smarty Rookie
Joined: 14 Jun 2006 Posts: 6
|
Posted: Mon Jun 19, 2006 4:16 pm Post subject: |
|
|
Ennumerating .tpl in a directory structure is easys and straightforward. Creating a list of http requests, by which all templates will be compiled is however rather difficult.
It's not the problem of "me compiling my .tpl files", I managed to do this by adding 4 lines to the smarty source code. It works, and I am satiesfied with it. This is just a suggestion to add a new feature, which might be useful for others too.
Regarding the link You posted: I am talking of a possibility to separate 1) from 2): compiling, without running. (No cache at all!) |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Jun 19, 2006 4:30 pm Post subject: |
|
|
sviver wrote: | Ennumerating .tpl in a directory structure is easys and straightforward. Creating a list of http requests, by which all templates will be compiled is however rather difficult.
It's not the problem of "me compiling my .tpl files", I managed to do this by adding 4 lines to the smarty source code. It works, and I am satiesfied with it. This is just a suggestion to add a new feature, which might be useful for others too. |
Hi.
I agree, it is easy and it isn't required in the standard distribution, IMHO because it is not a standard practice. Maybe consider posting your experience/solution as a HOWTO in the tips forum or at the wiki to help other users who may want to do such a thing. |
|
Back to top |
|
|