Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Reducing the number of plugins you want

 
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 420
Location: Kathmandu, Nepal

PostPosted: Thu Jan 05, 2012 9:30 am    Post subject: Reducing the number of plugins you want Reply with quote

Here is how I reduce the number of modifier plugins I have to use. I would like to write only one plugin that servers for all kinds of statistical requirements.

For example, when I need to count the number of produces found in a category, or number of members subscribed to a community, I write the short forms - forcing the use of one plugin only.

Code:

Total products: {'products'|statistics:$category_id}
Members: {'members'|statistics:$community_id}


Or other wise, I would need to write:
Code:

Total products: {$category_id|count_products}
Members: {$community_id|count_members}


Later version seems straight forward, but needs to use two different plugins. While, the earlier one needs only one plugin. Based on the two parameters that the statistics plugin receives, you can apply switch/case within the plugin and do the different calculations.

My modifier would look like: modifier.statistics.php
Code:

<?php
function smarty_modifier_statistics($section='', $extra_id=0)
{
   $extra_id = (int)$extra_id;
   $count = 0;
   switch($section)
   {
   case 'products':
      # count products here
      $count = ...
      break;
   case 'communities':
      # count members here
      $count = ...
      break;
   }
   
   return $count;
}
?>


Hope this helps you.
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks 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