Forum

Thread tagged as: Question, Runway

Check if any items in repeater

Hi,

I have a template that looks a bit like this:


<div class="info"> <img src="<perch:content id="card_one_image" type="image" label="Menu Card Background Image" width="1360" height="500" crop>" srcset=" <perch:content id="card_one_image" type="image" width="700" height="500" crop> 700w, <perch:content id="card_one_image" type="image" width="1000" height="500" crop> 1000w, <perch:content id="card_one_image" type="image" width="1360" height="500" crop> 1360w, <perch:content id="card_one_image" type="image" width="1920" height="500" crop> 1920w" sizes="(min-width: 720px) calc(50vw - 40px), calc(100vw - 20px)" alt="Menus" /> <perch:repeater id="menus" label="Menus"> <perch:before> <div class="text menus"> <h3>Our Menus</h3> <div class="menu-links"> </perch:before> <a data-no-swup href="<perch:content type="file" id="menu_file" label="Menu File">" target="_blank" rel="noreferrer noopener" class="button button-red-light"><perch:content id="menu_title" label="Menu Title" type="text"></a> <perch:after> </div> </div> </perch:after> </perch:repeater> </div> <a href="/gallery?gcat=<perch:content id="location" type="hidden">"> <div class="info"> <img src="<perch:content id="card_two_image" type="image" label="Gallery Card Background Image" width="1360" height="500" crop>" srcset=" <perch:content id="card_two_image" type="image" width="700" height="500" crop> 700w, <perch:content id="card_two_image" type="image" width="1000" height="500" crop> 1000w, <perch:content id="card_two_image" type="image" width="1360" height="500" crop> 1360w, <perch:content id="card_two_image" type="image" width="1920" height="500" crop> 1920w" sizes="(min-width: 720px) calc(50vw - 40px), calc(100vw - 20px)" alt="<perch:content id="full_location" type="hidden"> Experience" /> <div class="text"> <h3><perch:content id="full_location" type="hidden"> Experience</h3> <perch:content id="card_two_text" label="Gallery Card Text" type="textarea" editor="redactor" html editor-config="minimal" size="s"> </div> </div> </a>

I want to add a class to the first <div class="info"> if there are no items added to the repeater it contains. Is this possible?

Many thanks

Mike

Diagnostics below:

    Perch Runway: 3.1.1, PHP: 5.6.31, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $, with PDO
    Server OS: Darwin, apache2handler
    Installed apps: content (3.1.1), assets (3.1.1), categories (3.1.1), perch_forms (1.11), perch_twitter (4.0)
    App runtimes: <?php $apps_list = [ 'perch_twitter', 'perch_forms', 'casino36_crm' ];
    PERCH_LOGINPATH: /admin
    PERCH_PATH: /Users/mikeharrison/Google Drive/Client Work/Depict Creative/Casino 36 Website/Site/admin
    PERCH_CORE: /Users/mikeharrison/Google Drive/Client Work/Depict Creative/Casino 36 Website/Site/admin/core
    PERCH_RESFILEPATH: /Users/mikeharrison/Google Drive/Client Work/Depict Creative/Casino 36 Website/Site/admin/resources
    Image manipulation: GD
    PHP limits: Max upload 32M, Max POST 32M, Memory: 256M, Total max file upload: 32M
    F1: 3b606135b33e6a102526838f4152a807
    Resource folder writeable: Yes
    HTTP_HOST: casino.loc
    DOCUMENT_ROOT: /Users/mikeharrison/Google Drive/Client Work/Depict Creative/Casino 36 Website/Site
    REQUEST_URI: /admin/core/settings/diagnostics/
    SCRIPT_NAME: /admin/core/settings/diagnostics/index.php
Mike Harrison

Mike Harrison 37 points

  • 3 years ago
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Mike,

You can use conditional tags for this:

<perch:if not-exists="menus">
  <!--* the repeater with ID menus has no items *-->
</perch:if>

Thanks Hussein that did the trick. Don't know why but assumed that wouldn't work with repeater scoping so hadn't even tried it!