Hobo Cookbook

View Source



A convenience tag used to output a count and a correctly pluralised label. Works with any kind of collection such as an ActiveRecord association or an array.


<count:comments/> -> <span class="count">1 Comment</span>

<count:viewings/> -> <span class="count">3 Viewings</span>

The label can be customised using the label attribute, e.g.

<count:comments label="blog post comment"/> -> <span class="count">12 blog post comments</span>

Additional Notes

  • Use the prefix attribute to insert words before the count. If the prefix is “are” or “is” then it will be pluralised if needed:

      There <count:comments prefix="are"/> -> There <span class="count">is 1 Comment</span>
      There <count:viewings prefix="are"/> -> There <span class="count">are 3 Viewings</span>
  • Use the lowercase attribute to force the generated label to be lowercase:

      <count:comments lowercase/> -> <span class="count">1 comment</span>
  • Use the if-any attribute to output nothing if the count is zero. This can be followed by an <else> tag to handle the empty case:

      <count:comments if-any/><else>There are no comments</else>

Show Source


No comments to display