Forum

Thread tagged as: Question, Problem, Runway

Perch Runway Search Blank?

I am attempting to add a sitewide search function in the top layout which sends users to a results page (search.php). The following are my layout, master page, and template snippets.

Master Page (search.php)

<?php
perch_layout('global.top', [
        'page_title' => perch_page_title(true),
    ]);

    $query = perch_get('q');
    perch_content_search($query, array(
        'count'=>10,
        'excerpt-chars'=>300,
        'template'=>'search_result.html',
    ));

    perch_layout('global.footer');
?>

Search Function in global.top Layout

<?php
perch_search_form(array(
    'template'=>'search-nav.html'
));
?>

search_nav.html Template

<div id="search">
    <perch:form id="search" method="get" action="/search">
        <perch:input type="search" placeholder="search by keyword or sku" class="searchfield" /><perch:input type="submit" value="search" class="searchbutton" />
    </perch:form>
</div>
Kevin Wolff

Kevin Wolff 0 points

  • 3 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

What do you mean by "blank"?

I type something into the search field, hit the submit button, and then the browser navigates to the /search page, but the output on that page is empty without an error. One thing I did notice was that the URL lacked the query suffix of "?q=" after the /search.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Your search field has no ID

<perch:input type="search" placeholder="search by keyword or sku" class="searchfield" />

Aw jeez, silly mistake. facepalm So, now the URL completes properly and appends the field contents to a ?q=query, but the page has no output at all.

Here's my search field template now

<div id="search">
    <perch:form id="search" method="get" action="/search">
        <perch:input id="q" type="search" placeholder="search by keyword or sku" class="searchfield" /><perch:input type="submit" value="search" class="searchbutton" />
    </perch:form>
</div>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Do you have enough content entered for the search to be able to work?

I have some pages in the site and also a test product in the shop. I have been searching directly for a SKU or a keyword from its listing, but it doesn't show up.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You'll need more content before an SKU search returns anything useful. It should start working from around 30 items.

Would page content from other pages result in anything? I haven't filtered the search yet - it seems like the template should return with "0 results" instead of just an empty page without the static template pieces.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, it would return zero results.

Instead of showing the page framing from the template and saying there are no results like in this template here, it's completely blank on the page as if the template was not processed.

<perch:before>
    <h1>Search results for &#8220;<perch:search id="search_key" />&#8221;</h1>

    <perch:if exists="paging">
        <p><perch:search id="total" /> results</p>
    </perch:if>
        <ul>
</perch:before>

        <li class="<perch:search id="perch_item_odd" />">
            <h2><a href="<perch:search id="result_url" />"><perch:search id="result_title" /></a></h2>
            <perch:if exists="result_excerpt"><p class="excerpt">&hellip;<perch:search id="result_excerpt" encode="false" />&hellip;</p></perch:if>
            <p><a href="<perch:search id="result_url" />">
                <perch:if exists="result_pageNavText">
                    <perch:search id="result_pageNavText" />
                <perch:else />
                    <perch:search id="result_url" />
                </perch:if>
                </a></p>
        </li>

<perch:after>
    </ul>

    <perch:if exists="paging">
        <div class="paging">
            Page <perch:search id="current_page" /> of <perch:search id="number_of_pages" />
            <perch:if exists="not_first_page">
                <a href="<perch:search id="prev_url" encode="false" />">Previous</a>
            </perch:if>
            <perch:if exists="not_last_page">
                <a href="<perch:search id="next_url" encode="false" />">Next</a>
            </perch:if>
        </div>
    </perch:if>
</perch:after>


<perch:noresults>
    <perch:if exists="search_key">
        <h1>Search results for &#8220;<perch:search id="search_key" />&#8221;</h1>
    <perch:else />
        <h1>Search</h1>
    </perch:if>
    <perch:if exists="search_key">
        <p>Sorry, there are no results for &#8220;<perch:search id="search_key" />&#8221;.</p>
    </perch:if>
</perch:noresults>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you turned on debug to see what it outputs?

I couldn't figure out why debug mode was throwing an error because the file path looked nearly the same - the one difference was that the template called used an underscore, but the actual file used a dash. Good grief, thank you for putting up with my ridiculousness!