Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

compile method

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
sviver
Smarty Rookie


Joined: 14 Jun 2006
Posts: 6

PostPosted: Wed Jun 14, 2006 8:39 pm    Post subject: compile method Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Jun 15, 2006 12:14 am    Post subject: Reply with quote

Maybe you want something like this:

http://www.phpinsider.com/smarty-forum/viewtopic.php?t=8029#31132

But not having a templates_c setup really defeats the purpose of using Smarty, IMO.
Back to top
View user's profile Send private message
TGKnIght
Smarty Junkie


Joined: 07 Sep 2005
Posts: 580
Location: Philadelphia, PA

PostPosted: Thu Jun 15, 2006 1:09 am    Post subject: Reply with quote

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?


  1. Template designer writes template in Smarty syntax.
  2. PHP Coder uses $smarty->display() on said .tpl file.
  3. 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
View user's profile Send private message Visit poster's website
sviver
Smarty Rookie


Joined: 14 Jun 2006
Posts: 6

PostPosted: Sun Jun 18, 2006 9:00 pm    Post subject: Reply with quote

Hello boots

boots wrote:
Maybe you want something like this:

http://www.phpinsider.com/smarty-forum/viewtopic.php?t=8029#31132

But not having a templates_c setup really defeats the purpose of using Smarty, IMO.


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
View user's profile Send private message
sviver
Smarty Rookie


Joined: 14 Jun 2006
Posts: 6

PostPosted: Sun Jun 18, 2006 9:04 pm    Post subject: Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun Jun 18, 2006 11:20 pm    Post subject: Reply with quote

Your script can simulate a real http client instead of going up against the API. Or maybe just use wget? http://smarty.incutio.com/?page=CacheAndCompile
Back to top
View user's profile Send private message
sviver
Smarty Rookie


Joined: 14 Jun 2006
Posts: 6

PostPosted: Mon Jun 19, 2006 4:16 pm    Post subject: Reply with quote

boots wrote:
Your script can simulate a real http client instead of going up against the API. Or maybe just use wget? http://smarty.incutio.com/?page=CacheAndCompile


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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon Jun 19, 2006 4:30 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP