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

Prefilter

 
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 -> General
View previous topic :: View next topic  
Author Message
Terry151151
Smarty Regular


Joined: 06 May 2010
Posts: 37
Location: Sydney Australia

PostPosted: Sat Apr 05, 2014 10:33 pm    Post subject: Prefilter Reply with quote

In the prefilter is there any way to get the name and path of the template.
What I would like to do is if there is a php file with the same name as the template and in the same folder I would like to load it before the template is compiled.

Thanks in advance
Terry
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Apr 06, 2014 3:17 am    Post subject: Reply with quote

The second parameter of the filter is the template object.
$template->source->filepath should return the source template filepath
Back to top
View user's profile Send private message
Terry151151
Smarty Regular


Joined: 06 May 2010
Posts: 37
Location: Sydney Australia

PostPosted: Sun Apr 06, 2014 4:52 am    Post subject: Second thoughts Reply with quote

Now that I think about it I'm not sure the prefilter is the place to put it.

Where I need to put it is in a place after it is compiled and before where the compiled template is executed every time, so that the PHP code run and set up the variables for the template.

Any advice?
Terry
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Apr 06, 2014 10:24 am    Post subject: Reply with quote

Note: The a prefilter runs just once when the template source gets compiled. It does not run on each call of the page.

Variables needed should be assigned by the PHP script before you call the template. The other option would be to call a function plugin from within the template with does the assignments.
Back to top
View user's profile Send private message
Terry151151
Smarty Regular


Joined: 06 May 2010
Posts: 37
Location: Sydney Australia

PostPosted: Sun Apr 06, 2014 11:14 am    Post subject: Reply with quote

Unfortunately that gives me the same problem just in reverse. The PHP code now sets up the variables and then loads the template. Now it's the template that has to load the code. I was hoping to make it a little more transparent/automatic. What I have are small "components" that I load using "include" it would have been nice if I could have just invoked the include of the template and the code followed. But the function plugin might be a slightly better option than having the code load the template. I'll need to think about it.

Regards
Terry
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 -> General 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