|
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 |
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Thu Apr 30, 2009 4:08 pm Post subject: request - defining filter within template? |
|
|
I have a theme where I select an icon based on a file's extension.
so, it's basically one big if statement based on extension. I do this in various places in the site.
it would be the perfect place for a filter, for example,
<{$filename|file_img}>
However, I hate to make a global filter, because it's specific to the theme and would be useless without it. Is it possible that filters programmed in smarty can be put in a smarty template like functions can now be put there?
Then I could just put that filter in a theme library and include it where ever i need it.
I suppose it might require some type of return statement type function though. Or maybe the user could just set a special variable like $Smarty.return_value. I'm not really sure of all of the details. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Apr 30, 2009 4:18 pm Post subject: |
|
|
Use something that is theme aware?
Code: | <{get_icon theme=$theme filenname=$filename}> |
|
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Thu Apr 30, 2009 6:24 pm Post subject: |
|
|
mohrt wrote: | Use something that is theme aware?
Code: | <{get_icon theme=$theme filenname=$filename}> |
|
thanks. I can do that.
It's a pretty general problem though as there are big icons, small icons, and occasionally CSS classes associated with specific file types.
Maybe I was thinking about it the wrong way...
All of our applications are going to be specifically built for this theme, so it's not like we have selectable themes or anything.
Really it doesn't matter if they are smarty or php, the key thing is, i really don't want this filter to be in the same directory as the more general filters.
I think I will have the CMS add theme_dir/smarty_plugins to the list of plugin dirs, and put a filter (or a function) in there. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Apr 30, 2009 7:46 pm Post subject: |
|
|
Yes I was just going to mention using a separate plugin_dir for your theme and add the appropriate one. |
|
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
|