MENU

Count items

  Previous article Next article  

Small 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

CMSMS Troubleshooting information database


Buy Me A Coffee


  Comment Form

ReviewManager

Click here to open the form

ReviewManager

  0 Comments

No comments yet...

Buy Me A Coffee

CMS Made Simple - Tutorials, Tips and Tricks - CMSMS

Count items

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 1.11.12
  Last updated: 23-06-2018
  Comments: 0
  http://cms.ms/Tes8


Buy Me A Coffee




Advertisement


Ads help me to help you! Thanks!

Ads help me to help you! Buy products from these advertisers!