 |
Smarty
The discussions here are for Smarty, a template engine for the PHP programming language. Dedicated server web hosting provided by Guru-host.eu. |
| View previous topic :: View next topic |
| Author |
Message |
bimal Smarty Elite

Joined: 19 Apr 2007 Posts: 419 Location: Kathmandu, Nepal
|
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. _________________ Skype: pbimal
To hire instantly as a freelancer - https://www.odesk.com/o/profiles/users/_~~657b70cc7f2c616a/
Visit my website - http://bimal.org.np/ for more articles
800+ screenshots to learn about website mistakes: http://mistakes.sanjaal.com/ |
|
| 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
|