Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

request - defining filter within template?

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Thu Apr 30, 2009 4:08 pm    Post subject: request - defining filter within template? Reply with quote

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


Joined: 16 Apr 2003
Posts: 7365
Location: Lincoln Nebraska, USA

PostPosted: Thu Apr 30, 2009 4:18 pm    Post subject: Reply with quote

Use something that is theme aware?

Code:
<{get_icon theme=$theme filenname=$filename}>
Back to top
View user's profile Send private message Visit poster's website
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Thu Apr 30, 2009 6:24 pm    Post subject: Reply with quote

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


Joined: 16 Apr 2003
Posts: 7365
Location: Lincoln Nebraska, USA

PostPosted: Thu Apr 30, 2009 7:46 pm    Post subject: Reply with quote

Yes I was just going to mention using a separate plugin_dir for your theme and add the appropriate one.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3 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