Forum

Thread tagged as: Question

Return number of regions.

Hello,

I've seen a method of counting the number of repeaters within a page elsewhere in the forum. Is there a method of counting the number of regions in a page?

Regards Tony

Tony Astley

Tony Astley 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

There's not. What sort of circumstance would that be useful in?

CSS - In the past when using a repeater I have declared a class with a count appended to it e.g.

class="entries count<perch:content id="perch_item_count" />"

This allows me to apply a different set of styles (or jquery function) to the children of the container depending on the number of children - primarily low numbers of children (1, 2 or 3). So if there were only two items in the container I might switch to a 2 column view a breakpoint earlier.

There is a very, very convoluted way of doing this using the nth child selector in CSS, but it's not worth the headache.

Hi Tony,

I think your question was misleading as you're talking about a single region rather than multiple regions - and more specifically how many items are in said region. You could have classes setup within a perch:if statement, something like so:

<perch:if count="2">ClassName</perch:if><perch:if count="3">ClassName2</perch:if>

Or perch_item_count should give you a number for the amount of items within the region. Would that work for your needs?

perch_item_count works perfectly:

<div class="section count<perch:content id="perch_item_count"/>">

It might be the sheer volume of tags, methods and functions to take in - but as a designer (not developer) I always find it difficult to fathom when and where tags should be used. Some are restricted to templates, then templates come in different types (page|content|navigation / php/html) all with different abilities - I'll get there in the end but in the meantime excuse the 101 questions.

Practice makes perfect! The main thing to remember is, your pages are .php and any templates will be .html. If you ever need to see all your available tags to use within a template, you can use <perch:showall />.