|
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 |
tamlyn Smarty n00b
Joined: 21 May 2003 Posts: 1
|
Posted: Wed May 21, 2003 12:24 am Post subject: using custom functions (not plugins) |
|
|
I am thinkig of using smarty for my gallery script (http://singapore.sf.net) but I have a question:
My script uses functions which generate content on request to display on the page. Is it possible to do this with Smarty? I don't want to blindly assign the output of these functions to variables because then even content which is not displayed on that page will still have to be generated. I equally don't want to create a plugin for each function because there are many and they depend on each other.
I just want to be able to write {something} and that be replaced by the result of running something()
T. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed May 21, 2003 12:34 am Post subject: |
|
|
You might want to consider using Smarty assigned objects. Since an object can expose many functions, it is similar to what you want. Otherwise, you can also explicitly register functions with Smarty, but they must support the Smarty calling and return interfaces. Why, you can even create a single generic function that supports the Smarty interface but then delegates to your custom functions based on a passed parameter from the template.
Smarty is EXTREMELY flexible.
See: http://smarty.php.net/manual/en/advanced.features.php
and http://smarty.php.net/manual/en/plugins.php
EDIT:
Lastly, Smarty is probably overkill in this situation. You can probably get away doing a custom regex if all you need is textual replacement. If you STILL want Smarty, you can custom regex in a pre-filter.
Perhaps on a side-note: your application code should be responsible for generating the right amount of data for your templates instead of delegating that to your template code. |
|
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
|