Quirky search block behavior

Permalink
I was having difficulties getting the search block to work properly on a site I moved from a local setup to a hosted server, but I got it to work.

I built a site with a search block in the header on each page type. (This is a manually added block, not added to the theme.) I added the block early in the site setup process to return search results on another page (/search-results/). The search results page has another search block in the main section of the page to display the results.

I could not get any results to appear until I deleted the search block in the header, added a new search block to the main section of the search results page (set to return results on that same page). Once I got the search to work for that individual block, I added it back to the header of that same page (to be consistent with the rest of the site).

I was literally pulling my hair out, changing index options, re-indexing, etc. Deleting the search blocks on the results page and re-installing is the only thing that worked.

Sherm Stevens
http://www.invision-studios.com

invision
 
OsamaG replied on at Permalink Reply
Hello there ,
As i can understand your problem was that you added the search block manually to the header of your theme, so every page will have search block in the header , even the /search-results page so that it will miss up the layout of the theme in that page!

If this is your problem , You should do the following :
* check to see in the header ,if the page URL is the same as "search-result" page URL ,it will not add the block manually.
* add the block to the "/search-results" page in the edit mode in the main content.

In your header.php in your theme do the following :
// get the url of the current page.
$URL = $this->url($this->getCollectionObject()->cPath);
// check to see if it is the same as the "/search-results" page
if($URL == '/test/index.php/search-results'){
       // don't do anything here
}else{
       // add the search block
       // I am assuming that you add the search block to the scrapbook
        $block = Block::getByName('Search_Block');
        if( is_object($block) ) $block->display();
}


Hope this will help!
jordanlev replied on at Permalink Reply
jordanlev
I have another solution that I have found works a lot better for me: for search boxes that are in the header of every page, I don't use the search block at all but instead just hard-code an html form. As long as your form has an input text field with the name "query", and the form's action points to the search results page you set up, it works great, and also gives you more flexibility to style it the way you want.

For example:
<form method="get" action="<?php echo View::url('/search-results') ?>">
  <input type="text" name="query" class="whatever" />
  <input type="submit" value="go" class="anything" />
</form>