Check if template outputting anything

  • Is there a way to check if a region is outputting anything if that regions template is being filtered via an if statement?


    I am filtering the template via a date selector as it is a list of courses. So any courses in the past are not output. However if there are no courses output on the page then I want to display a message saying no courses currently available please contact blah blah, rather than just an empty space.


    Courses page:

    Product Card template:

    Any help muchly appreciated. Many thanks!

  • drewm

    Approved the thread.
  • Hello splendid_rob


    If you move your filtering logic outside of the template, you can use the perch:noresults tag to display the "no courses currently available.." message.


    PHP
    1. perch_shop_products([
    2. 'template' => 'products/product-card.html',
    3. 'category' => perch_get('cat'),
    4. 'filter' => 'course_end_date',
    5. 'match' => 'gte',
    6. 'value' => $today
    7. ]);