Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
Hi,

I'm building a (small) bibliography into a a website I am working on. Effectively I want the bibliography to run through one file, bibliography.php. Currently I have the bibliography set up as a cloneable template with each page denoting an entry in the bibliography. Here is a simplified version of the code I am using to output the listings in the bibliography and each individual item.

Code: Select all
<cms:if k_is_page>
   <!-- output single entry in bibliography -->
   <h1><cms:show k_page_title /></h1>
   <p><!-- other information from given entry --></p>
<cms:else />
   <cms:pages masterpage='bibliography.php' limit='10' paginate='1'>
      <h2><cms:show k_page_title /></h2>
      <p><!-- other information from given entry --></p>
      <hr />
   </cms:pages>
</cms:if>

<cms:search_form />

<div class="search-results">
   <h2>Showing Results for: [Keyword]</h2>
   <cms:search masterpage='bibliography.php' limit='10'>
      <h3><cms:show k_page_title /></h3>
      <p><!-- other information from given entry --></p>
      <hr />
      <cms:no_results>
         <h3>No pages found for <cms:show k_search_query /></h3>
      </cms:no_results>
   </cms:search>
</div>


This all works as expected but I am having a bit of difficulty trying to figure out how to display the search results instead of the page listings. I have looked around for a way to detect if the page is pulling search results and display the results instead of the listings content but I can't seem to figure it out. Any help would be fantastic, cheers!
Hi neutraltone :)

I think detecting the presence of the search query string 's' in the URL should be sufficient:
Code: Select all
<cms:if k_is_page>
    <!-- output single entry in bibliography -->
    <h1><cms:show k_page_title /></h1>
    <p><!-- other information from given entry --></p>
<cms:else />
   <cms:set searching="<cms:gpc method='get' var='s' />" />

   <cms:if "<cms:not_empty searching />">
        <div class="search-results">
            <h2>Showing Results for: <cms:show searching /></h2>
            <cms:search masterpage='bibliography.php' limit='10'>
                <h3><cms:show k_page_title /></h3>
                <p><!-- other information from given entry --></p>
                <hr />
                <cms:no_results>
                    <h3>No pages found for <cms:show k_search_query /></h3>
                </cms:no_results>
            </cms:search>
        </div>
    <cms:else />
        <cms:pages masterpage='bibliography.php' limit='10' paginate='1'>
            <h2><cms:show k_page_title /></h2>
            <p><!-- other information from given entry --></p>
            <hr />
        </cms:pages>
    </cms:if>
</cms:if>

<cms:search_form processor=k_template_link />
I also added the processor parameter to the search_form tag to make sure the visitor lands on the list view after a search and not potentially on the page view. Let us know if this works and if you have any questions.
@neutraltone, while @cheesypoof's solution will definitely work, may I ask why you are not using the regular method of using a separate template for displaying only search results?

For example, we can use an uncloned template named 'search.php' and place the search relevant part of the code in there.
Code: Select all
<div class="search-results">
   <h2>Showing Results for: [Keyword]</h2>
   <cms:search masterpage='bibliography.php' limit='10'>
      <h3><cms:show k_page_title /></h3>
      <p><!-- other information from given entry --></p>
      <hr />
      <cms:no_results>
         <h3>No pages found for <cms:show k_search_query /></h3>
      </cms:no_results>
   </cms:search>
</div>


The search form on all other pages can lead to the search template using
Code: Select all
<cms:search_form processor="<cms:link 'search.php' />" />
I think I must have my wires slightly crossed. I did try that method but I couldn't figure out how to get the URLs to be /bibliography/search (or something similar to indicate that I was searching within the bibliography). I will have another stab at it.

This is my first time building a site with Couch and it's been fairly painless although the scope of the project I am working on has become somewhat more complex as time has gone on. This in turn hasn't made it the best project to pickup a new content management system as the occasional kink arrises.

I'll let you know how I get on.
4 posts Page 1 of 1