|
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 |
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Thu Jan 05, 2012 9:30 am Post subject: Reducing the number of plugins you want |
|
|
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 |
|
|
|
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
|