ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How to get search results to show up in my main template rather than the search template?

December 07, 2007 6:50pm

Subscribe [2]
  • #1 / Dec 07, 2007 6:50pm

    jlahijani

    11 posts

    Hello.

    I made a template which I am using for pretty much every page on my site.  I also have the simple search form on it, which as the documentation states, allows you to choose the template (and its template group) that the search results should display on, like this:

    {exp:search:simple_form search_in="everywhere" result_page="mytemplategroup/mymaintemplate"}
    ...
    {/exp:search:simple_form}

    Unfortunately, it seems that I cannot get the search results to display on my main template due to how EE handles the search results template tags.  If the {exp:search:search_results} loop exists on a template, no matter if it is in a conditional like below, it automatically assumes that a search has been conducted.  This is forcing me to keep the search results on a separate template.

    Ideally, I would like to do something like this:

    {if ("{segment_1}" == "search"}
      <table>
      {exp:search:search_results switch="resultRowOne|resultRowTwo"}
      <tr>
        <td class="{switch}"><a href="http://{page_url}">{title}</a></td>
        <td class="{switch}">{excerpt}</td>
      </tr>
      {/exp:search:search_results}
      </table>
    {if:else}
      {title}
      {body}
    {/if}

    I also found this post from a while ago, however I do not understand it too well and it seems that the technique is dated:
    http://ellislab.com/forums/viewthread/36481/

    Any help would be appreciated!

  • #2 / Dec 07, 2007 7:20pm

    Sue Crocker

    26054 posts

    Have you considered making the search results template look more like your regular site? That’s what I do.

  • #3 / Dec 07, 2007 7:24pm

    jlahijani

    11 posts

    That’s crossed my mind, but that violates the principles of DRY (don’t repeat yourself) and furthermore, every time I want to change my main template, I’d have to do it again on my search results template, unless my search results template is EXTREMELY simplified.

  • #4 / Dec 07, 2007 7:52pm

    Sue Crocker

    26054 posts

    every time I want to change my main template, I’d have to do it again on my search results template, unless my search results template is EXTREMELY simplified.

    Actually, that’s not true.

    I take all of my designs and break them down to embeds like:

    topnav, leftnav, rightnav, footer, header, etc. The main blocks that would be changed if the design changed.

    So if I want to change my right nav code, I just change the embedded template.

    Shop In Bel Air

    If you search for food, you’ll get two results, and the page looks much the same as before.

    There are 4 embeds on this results page. Not a very sophisticated design, but it’s what the client wanted.

  • #5 / Dec 07, 2007 8:03pm

    jlahijani

    11 posts

    Perfect.

    I never realized that EE could embed templates within other templates:
    http://expressionengine.com/docs/templates/embedding_templates.html

    I was actually looking for this functionality but I worked around it.

    Now I just need to break my main template up into small templates and I should be good.

    Thank you very much.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases