Forum

Thread tagged as: Problem, Error, Forum

No Results not displaying if slug is empty.

Hello,

I have been creating a perch website where we have been using collections, then search the display the collection information using the slug. i.e. "properties/property?s=test-house" But when there is no slug, shouldn't the no results code show?

Perch Debug:

Perch Runway: 2.8.31
Production mode: Production (100)
Installed apps: content (2.8.31), assets (2.8.31), categories (2.8.31), perch_blog (5.0), distributors (1), perch_forms (1.8.3), collection_2 (2.8.31)
DB driver: PDO
DB tables: perch2_backup_plans (0), perch2_backup_resources (0), perch2_backup_runs (0), perch2_blog_authors (1), perch2_blog_comments (0), perch2_blog_index (71), perch2_blog_posts (3), perch2_blog_posts_to_tags (0), perch2_blog_sections (1), perch2_blog_tags (0), perch2_blogs (1), perch2_categories (4), perch2_category_counts (0), perch2_category_sets (2), perch2_collection_index (281), perch2_collection_items (9), perch2_collection_revisions (2), perch2_collections (1), perch2_content_index (798), perch2_content_items (86), perch2_content_regions (22), perch2_forms (2), perch2_forms_responses (4), perch2_navigation (0), perch2_navigation_pages (0), perch2_page_routes (0), perch2_page_templates (19), perch2_pages (12), perch2_resource_log (316), perch2_resource_tags (0), perch2_resources (155), perch2_resources_to_tags (0), perch2_settings (24), perch2_user_passwords (0), perch2_user_privileges (37), perch2_user_role_privileges (16), perch2_user_roles (2), perch2_users (1)
Users: 1
App runtimes:
<?php
    $apps_list = array(
        'content', 
        'categories',
        'perch_blog',
        'perch_forms',
    );
Scheduled tasks for perch_blog: delete_spam_comments (1440 mins)
Editor plug-ins: markitup, redactor
H1: 0753a79ad0e50b614820786ef3e5df2c
L1: fd6b37510a50ca9e7ca48cbbf76c0333
F1: 2edba60ed1f613d6dd804feb202456a2
headerColour: #0c1a3a
content_singlePageEdit: 1
helpURL:
siteURL: /
hideBranding: 0
content_collapseList: 1
lang: en-gb
update_2.8.31: done
perch_blog_update: 5.0.1
headerScheme: dark
update_runway_2.8.31: done
latest_version: 2.8.15
on_sale_version: 2.8.31
dashboard: 0
hide_pwd_reset: 0
content_hideNonEditableRegions: 0
content_frontend_edit: 0
logoPath: /admin/resources/logo-dark.png
perch_blog_post_url: /news/post?s={postSlug}
perch_blog_site_name:
perch_blog_slug_format: %Y-%m-%d-{postTitle}
perch_blog_akismet_key:
perch_blog_max_spam_days: 0
perch_blog_comment_notify: 0
PERCH_DEVELOPMENT: 10
PERCH_STAGING: 50
PERCH_PRODUCTION: 100
PERCH_SITEPATH: /Users/chris/Repositories/Stevens Property Management/stevens-property-core-site/build
PERCH_SCHEDULE_SECRET: j4d3BIMgMKpsupCg
PERCH_DB_USERNAME: root
PERCH_DB_SERVER: localhost
PERCH_DB_DATABASE: stevens_perch
PERCH_DB_PREFIX: perch2_
PERCH_EMAIL_FROM: Chris@rootstudio.co.uk
PERCH_EMAIL_FROM_NAME: Chris Burns
PERCH_LOGINPATH: /admin
PERCH_PATH: /Users/chris/Repositories/Stevens Property Management/stevens-property-core-site/build/admin
PERCH_CORE: /Users/chris/Repositories/Stevens Property Management/stevens-property-core-site/build/admin/core
PERCH_RESFILEPATH: /Users/chris/Repositories/Stevens Property Management/stevens-property-core-site/build/admin/resources
PERCH_RESPATH: /admin/resources
PERCH_HTML5: 1
PERCH_TZ: UTC
PERCH_DEBUG: 1
PERCH_RUNWAY: 1
PERCH_ERROR_MODE: DIE
PERCH_DATE_LONG: %d %B %Y
PERCH_DATE_SHORT: %d %b %Y
PERCH_TIME_SHORT: %H:%M
PERCH_TIME_LONG: %H:%M:%S
PERCH_RUNWAY_ROUTED:
PERCH_STRONG_PASSWORDS:
PERCH_PREVIEW_ARG: preview
PERCH_TEMPLATE_PATH: /Users/chris/Repositories/Stevens Property Management/stevens-property-core-site/build/admin/templates
PERCH_DEFAULT_DOC: index.php
PERCH_DEFAULT_EXT: .php
PERCH_PRODUCTION_MODE: 100
PERCH_RWD:
PERCH_HTML_ENTITIES:
PERCH_SSL:
PERCH_STRIPSLASHES:
PERCH_PROGRESSIVE_FLUSH: 1
PERCH_PARANOID:
PERCH_FORCE_SECURE_COOKIES:
PERCH_PASSWORD_MIN_LENGTH: 6
PERCH_MAX_FAILED_LOGINS: 10
PERCH_AUTH_LOCKOUT_DURATION: 1 HOUR
PERCH_VERIFY_UPLOADS:
PERCH_AUTH_PLUGIN:
PERCH_DB_CHARSET: utf8
PERCH_DB_PORT:
PERCH_DB_SOCKET:
PERCH_SESSION_TIMEOUT_MINS: 20
PERCH_APPS_EDITOR_PLUGIN: markitup
PERCH_APPS_EDITOR_MARKUP_LANGUAGE: textile
HOSTING SETTINGS

PHP: 5.6.10
Zend: 2.6.0
OS: Darwin
SAPI: cgi-fcgi
Safe mode: not detected
MySQL client: mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $
MySQL server: 5.5.42
Free disk space: 648.16 GB
Extensions: Core, date, ereg, libxml, openssl, pcre, sqlite3, zlib, bcmath, bz2, calendar, ctype, curl, dom, hash, fileinfo, filter, ftp, gd, SPL, iconv, intl, json, ldap, mbstring, session, standard, mysqlnd, mysqli, PDO, pdo_mysql, pdo_sqlite, Phar, posix, readline, Reflection, mysql, SimpleXML, soap, sockets, exif, tokenizer, wddx, xml, xmlreader, xmlwriter, xsl, zip, cgi-fcgi, imap, gettext, mcrypt, yaz, pgsql, pdo_pgsql, xdebug
GD: Yes
ImageMagick: No
PHP max upload size: 32M
PHP max form post size: 32M
PHP memory limit: 128M
Total max uploadable file size: 32M
Resource folder writeable: Yes
Session timeout: 24 minutes
Native JSON: Yes
Filter functions: Yes
Transliteration functions: Yes
PHP_FCGI_CHILDREN: 4
PWD: /Applications/MAMP/fcgi-bin
PHP_FCGI_MAX_REQUESTS: 200
__CF_USER_TEXT_ENCODING: 0x1F5:0x0:0x0
ORIG_SCRIPT_NAME: /fcgi-bin/php5.6.10.fcgi
ORIG_PATH_TRANSLATED: /Users/chris/Repositories/Stevens Property Management/stevens-property-core-site/build/admin/core/settings/diagnostics/index.php
ORIG_PATH_INFO: /admin/core/settings/diagnostics/index.php
ORIG_SCRIPT_FILENAME: /Applications/MAMP/fcgi-bin/php5.6.10.fcgi
SCRIPT_NAME: /admin/core/settings/diagnostics/index.php
REQUEST_URI: /admin/core/settings/diagnostics/?extended
QUERY_STRING: extended
REQUEST_METHOD: GET
SERVER_PROTOCOL: HTTP/1.1
GATEWAY_INTERFACE: CGI/1.1
REDIRECT_URL: /admin/core/settings/diagnostics/index.php
REDIRECT_QUERY_STRING: extended
REMOTE_PORT: 61227
SCRIPT_FILENAME: /Users/chris/Repositories/Stevens Property Management/stevens-property-core-site/build/admin/core/settings/diagnostics/index.php
SERVER_ADMIN: you@example.com
DOCUMENT_ROOT: /Users/chris/Repositories/Stevens Property Management/stevens-property-core-site/build
REMOTE_ADDR: ::1
SERVER_PORT: 80
SERVER_ADDR: ::1
SERVER_NAME: stevenspropertymanagement.local
SERVER_SOFTWARE: Apache
PATH: /usr/bin:/bin:/usr/sbin:/sbin
HTTP_ACCEPT_ENCODING: gzip, deflate
HTTP_REFERER: https://stevenspropertymanagement.local/admin/core/settings/diagnostics/
HTTP_ACCEPT_LANGUAGE: en-us
HTTP_USER_AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.7 (KHTML, like Gecko) Version/9.1.2 Safari/601.7.7
HTTP_COOKIE: _ga=GA1.2.69910111.1469094347; _gat=1; PHPSESSID=f5df256032cdb155adb839c4c44d3fc6; cmsa=1
HTTP_CONNECTION: keep-alive
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_HOST: stevenspropertymanagement.local
REDIRECT_STATUS: 200
REDIRECT_HANDLER: php-fastcgi
FCGI_ROLE: RESPONDER
PHP_SELF: /admin/core/settings/diagnostics/index.php
REQUEST_TIME_FLOAT: 1470398540.43
REQUEST_TIME: 1470398540
argc: 1

local: /core/property.php

<?php
// Include the header. You can find this in tempates/layouts/global
perch_layout('global/header', [
    'class' => 'property',
]);

    $itemData = perch_collection('properties', [
        'template'      => 'properties/properties_data.html',
        'filter'        => 'slug',
        'match'         => 'eq',
        'value'         => perch_get('s'),
        'count'         => 1,
        'skip-template' => true,
        'raw'           => true,
    ]);
?>
    <div class="wrapper">
        <?php perch_layout('sidebar/search'); ?>

        <div class="main +clearfix">
                <?php perch_template('content/property/property_info.html', $itemData); ?>

                <div class="media">
                    <?php
                    perch_template('content/property/property_carousel.html', $itemData);
                    perch_template('content/property/property_map.html', $itemData);
                    ?>
                </div>
        </div>
    </div>
<?php
// Include the footer. You can find this in tempates/layouts/global
perch_layout('global/footer');

Property Data

<perch:content id="slug" for="address1" type="slug" suppress="true" />

<perch:content id="type" type="select" label="Type of Property" options="Rural|rural, Town|town" allowempty="false" required="false" />
<perch:content id="furnishings" type="select" label="property" options="Furnished|furnished, Unfurnished|unfurnished" allowempty="false" required="false" />
<perch:content id="bedrooms" type="select" label="bedrooms" options="1, 2, 3, 4, 5, 6, 7, 8, 9, 10" allowempty="false" required="false" />
<perch:content id="price" type="text" label="Price pcm: £" help="Please do not put the £ sign"/>

<perch:content id="address1" title="true" type="text" label="Address 1" required="true" divider-before="Address"/>
<perch:content id="address2" type="text" label="Address 2"/>
<perch:content id="address3" type="text" label="Address 3"/>
<perch:categories id="areas" set="areas" display-as="checkboxes" label="City" required="true" help="Please only tick one."/>
<perch:content id="county" type="select" label="County" options="Lincolnshire|lincolnshire, Nottinghamshire|nottinghamshire, Rutland|rutland, Leicestershire|leicestershire, Derbyshire|derbyshire, Northamptonshire|northamptonshire" allowempty="false" required="false" />
<perch:content id="postcode" type="text" label="Postcode"  required="true"/>

<perch:content id="description" type="textarea" label="House Description" html="true" editor="redactor" divider-before="Description" />
<perch:content id="accommodation" type="textarea" label="Accommodation" html="true" editor="redactor"/>

<perch:content id="epc" type="text" label="epc"/>



<perch:content id="house_image" type="image" label="House Image" bucket="house" required="true"/>
<perch:content id="house_image" type="image" bucket="house" crop="true" width="220" height="175"">
<perch:content id="house_image_alt" type="text" label="Alt text" required="true" />

<perch:repeater id="carousel" label="Carousel" max="12">
    <perch:content type="image" id="carousel_image" label="Image" bucket="house"/>
    <perch:content type="image" id="carousel_image" label="Image" bucket="house" crop="true" height="290" width="380"/>
    <perch:content type="image" id="carousel_image" label="Image" bucket="houses" crop="true" width="150" height="150"/>
    <perch:content type="text" id="carousel_alt" label="Description"/>
</perch:repeater>

Property Info

<article class="information">
    <header class="information__header">
        <div class="information__title">
            <perch:if exists="address1"><perch:content id="address1" />,</perch:if>

            <perch:if exists="address2"><perch:content id="address2" />,</perch:if><br/>
            <perch:categories id="areas">
                <perch:before>
                    <perch:category id="catTitle"/>,
                </perch:before>
            </perch:categories>
            <perch:content id="county" />

        </div>
        <div class="information__title--sub">
            £<perch:content id="price" /> monthly
        </div>
    </header>
    <div class="information__heading">Description</div>
    <div class="information__content rich-text">
        <perch:content id="description" html="true"/>
    </div>
    <div class="information__heading">Accommodation</div>
    <div class="information__content rich-text">
        <perch:content id="accommodation"html="true" />
    </div>
    <footer class="information__footer">
        <a href="<perch:content id="epc" />" class="button">Download EPC</a>
    </footer>
</article>

<perch:noresults>
    Sorry Property Not found.
</perch:noresults>

Thank you.

Chris Burns

Chris Burns 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you're using skip-template then the template isn't being used for display. In that case you'll need to handle the result yourself.

Would this still be the case when using perch_template() to render the collection data?

If no results are found on the collection $itemData is returned as an empty array. Checking through the code the calls are being made in Perch core to trigger the $Template->use_noresults() method however nothing is being rendered as a result.

Drew McLellan

Drew McLellan 2638 points
Perch Support

perch_template() should handle that, yes.

I don't quite follow from your code why you're using skip-template and then re-templating here at all. Why no just let the function run as normal?

I am using the content of Property Data In three different places on the page, so it was suggested that I use skip-template. This method does only one query on property data instead of three. That was the reason that I used skip-template

Drew McLellan

Drew McLellan 2638 points
Perch Support

Right, you're using it in three different places, but it looks like they could all be one template as they're all clustered together in the page.

Yes, They could all be in one template, but I split them up into three templates to keep each component separate in the code. Would the solution to get this to show being to merge the three templates?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I would create a meta template that brought the three together:

<div class="wrapper">
    <perch:layout path="sidebar/search" />

    <div class="main +clearfix">
        <perch:template path="content/property/property_info.html" />

        <div class="media">
            <perch:template path="content/property/property_carousel.html" />
            <perch:template path="content/property/property_map.html" />
        </div>
    </div>
</div>

https://docs.grabaperch.com/docs/templates/includes/

Having a parent template seemed have fixed the problem. Thank you.