Count items
Previous article Next articleSmall User Defined Tag that count items in an array, useful for several modules like News, CGBlog, Products, etc.
This article originates from the former CMS Made Simple Wiki, the original author is Elijah Lofgren.
Note: The following Smarty tag has the same functionality! I post this UDT anyway because it might be a inspiration help to you for other purposes...
Alternative method
{$itemcount = $items|@count}Create a new User Defined Tag, named "count_items"
count_items
$items = cmsms()->GetSmarty()->get_template_vars('items');$smarty->assign('itemcount', count($items));
How to use
Template example
{count_items}{if $itemcount}
<p>There are {$itemcount} items on this website</p>
<!-- start normal template -->
{foreach from=$items item=entry}
{/foreach}
<!-- end normal template -->
{else}
<p>There are no items...</p>
{/if}
Working example
Comment Form
ReviewManager
ReviewManager
0 Comments
No comments yet...