|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Terry151151 Smarty Regular
Joined: 06 May 2010 Posts: 37 Location: Sydney Australia
|
Posted: Sat Apr 05, 2014 10:33 pm Post subject: Prefilter |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Apr 06, 2014 3:17 am Post subject: |
|
|
The second parameter of the filter is the template object.
$template->source->filepath should return the source template filepath |
|
Back to top |
|
Terry151151 Smarty Regular
Joined: 06 May 2010 Posts: 37 Location: Sydney Australia
|
Posted: Sun Apr 06, 2014 4:52 am Post subject: Second thoughts |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Apr 06, 2014 10:24 am Post subject: |
|
|
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 |
|
Terry151151 Smarty Regular
Joined: 06 May 2010 Posts: 37 Location: Sydney Australia
|
Posted: Sun Apr 06, 2014 11:14 am Post subject: |
|
|
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 |
|
|
|
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
|