How can I include search results in an override template?

Author Message

Espen R

Thursday 25 May 2006 10:36:02 am

I want to display the search results from a searchbox on the same page. This page has a full node override template.

So I thought I could just include a copy of search.tpl (which I placed in the templates folder of my siteview) in the override template for that node:

{include uri='design:search.tpl'}

and then set the action attribute of the search form (on the same page) to point to the url of the same page instead of '/content/search/'.

<form action={$node.url_alias|ezurl} method="get">

But it doesn't work. It does display the included template, but with no sesults. Seems like it cant's pick up the search text variable.

What's the correct way of doing this?

Help would be very appreciated.

Marcin Drozd

Friday 26 May 2006 1:32:43 am

Hi Espen

There is

{include name=Result
         uri='design:content/searchresult.tpl'
         search_result=$search_result}

in standard search.tpl
You should use <form action={'/content/search/'|ezurl} method="get"> and you can change (override) the searchresult.tpl or create new one (ex. my_searchresult.tpl) and include its: uri='design:content/my_searchresult.tpl'

http://ez-publish.pl

Espen R

Friday 26 May 2006 8:13:07 am

Thank you for your kind advise. But that's not what I want to do.

I want to include the full search template (or just the searchresults.tpl) in another spesific node override so that I can retain the place in the nav hierarchy and hence also retain the nav tree menu in the same state.

If I just point the search form at /content/search/ there will be a jump out of context for the user. And I don't want that.

A kind soul on #ezpublish pointed me in the direction of using ezhttp(var,get) to transport the search text through the node template, but still it will not work. It doesn't display any search results, but at least it echoes the search text now.

Maybe I am doing something wrong, or maybe there are limitations in what's possible to do. I don't know.

Further assistance is very appreciated.

Using v3.6.7 btw.

Marcin Drozd

Sunday 28 May 2006 8:39:57 am

Hi
Because you dont use /content/search action, you have empty search result.
There is $search_text in search.tpl but this variable is set in kernel/content/search.php

$searchText = '';
if ( $http->hasVariable( "SearchText" ) )
{
    $searchText = $http->variable( "SearchText" );
}

and

$tpl->setVariable( "search_text", $searchText );

You can use fetch function in your full node override template like:

{def $search=fetch( 'content', 'search',
                    hash( 'text',     ezhttp( 'SearchText', 'get' ) ) )}
{foreach $search.SearchResult as $matched_node}
    {$matched_node.name|wash} <br />
{/foreach}

more: http://ez.no/doc/ez_publish/technical_manual/3_7/reference/modules/content/fetch_functions/search

use hash( 'text', ezhttp( 'SearchText', 'get' ) ) instead of hash(text,$search_text)

http://ez-publish.pl

Espen R

Tuesday 30 May 2006 6:58:06 am

Thank you. I will try this.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.