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.

eZ debug

Timing: Jan 18 2025 18:17:00
Script start
Timing: Jan 18 2025 18:17:00
Module start 'layout'
Timing: Jan 18 2025 18:17:00
Module start 'content'
Timing: Jan 18 2025 18:17:02
Module end 'content'
Timing: Jan 18 2025 18:17:02
Script end

Main resources:

Total runtime2.0080 sec
Peak memory usage4,096.0000 KB
Database Queries63

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0086 588.1719152.6563
Module start 'layout' 0.00860.0040 740.828139.5078
Module start 'content' 0.01261.9939 780.3359562.8828
Module end 'content' 2.00650.0015 1,343.218816.0938
Script end 2.0080  1,359.3125 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00390.1962160.0002
Check MTime0.00150.0728160.0001
Mysql Total
Database connection0.00300.149510.0030
Mysqli_queries1.933996.3089630.0307
Looping result0.00100.0497610.0000
Template Total1.961797.720.9808
Template load0.00250.122420.0012
Template processing1.959297.569520.9796
Template load and register function0.00010.004710.0001
states
state_id_array0.00140.068410.0014
state_identifier_array0.00230.113820.0011
Override
Cache load0.00210.1040410.0001
Sytem overhead
Fetch class attribute can translate value0.00080.040020.0004
Fetch class attribute name0.00290.143960.0005
XML
Image XML parsing0.00060.031220.0003
class_abstraction
Instantiating content class attribute0.00000.001080.0000
General
dbfile0.00140.0691160.0001
String conversion0.00000.000540.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
6content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 29
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs