Module

Archived
Forum
(read-only)

Google Custom Search

ExpressionEngine 2, ExpressionEngine 3, ExpressionEngine 4

Back to this add-on's main page
View Other Add-ons From Derek Hogue

     

{exp:google_custom_search:keywords keywords=”{segment_3}”}

Bug (Resolved)

Delaris Dev
Delaris Dev

I have just upgraded to EE3 and am having a problem with the search.

I updated my results page to use the new variable names.  We have a H1 on the page to show the search term, but it is blank.

I am using the tag from the documentation.

{exp:google_custom_search:keywords keywords=”{segment_3}”}

Sample result:

http://coosbay.org/search/results/98ac6b4b086b5a2f47677b15e786d9ba

Derek Hogue
# 1
Developer
Derek Hogue

You may have found a bug! Can you try this revised file - drop it in to replace your copy on the server and try again? https://dsh.re/c48df

Delaris Dev
# 2
Delaris Dev

It took the site down
This page isn’t working coosbay.org is currently unable to handle this request.
HTTP ERROR 500

Derek Hogue
# 3
Developer
Derek Hogue

Looking at your site right now, the page (and the keywords) appear to be working?

Delaris Dev
# 4
Delaris Dev

Thank you for your prompt responses!

When the fix you sent didn’t work, I changed the template to put the H1 well inside the ‘exp:google_custom_search:results’ tags.

The site is live and I wanted to fix it fast. 

The original problem still exists, but solving it is no longer an urgent issue.  The no results will not have the styled H1 piece, but it works for now.

Derek Hogue
# 5
Developer
Derek Hogue

I just tested this change on a couple of other sites, and it worked without issue. Did you unzip the file in the link first?

Delaris Dev
# 6
Delaris Dev

Yes, I did.  I was away from the office though and didn’t have time to look into what was going on.  I will try it again.

Delaris Dev
# 7
Delaris Dev

http://coosbay.org/search/results/44e84aed392e0eaef82865e75bf052b2

It is working now.  The no results if statement it blank, however, see the link above.

{if no_results}Sorry, your search returned no results.{/if}
  {if count == 1}
    About {absolute_results} results
    <ol>{/if}
    <li>

Derek Hogue
# 8
Developer
Derek Hogue

Are you nesting the exp:google_custom_search tag within another tag (like a channel:entries tag)?

Delaris Dev
# 9
Delaris Dev

{embed=“wrappers/.main”}

{exp:stash:set name=“body-id”}search{/exp:stash:set}
{exp:stash:set name=‘css-section’}search{/exp:stash:set}
{exp:stash:set name=‘page-title’}Search Results{/exp:stash:set}

{exp:stash:set name=“main-content”}
  <div class=“row”>
  <div class=“span12”>
  <h1 class=“well”>Searching for: {exp:google_custom_search:keywords keywords=”{segment_3}”}</h1>
  </div>
</div>
<div class=“row”>
  <div class=“span12”>
  {exp:google_custom_search:results cse=“xxx” api_key=“xxx” keywords=”{segment_3}” replace_title=” | City of Coos Bay”}
    {if no_results}Sorry, your search returned no results.{/if}
  {if count == 1}
    About {absolute_results} results

    {/if}    
  1.     {if image}[url=”{url}”]{thumbnail_image} {/if}     <a href=”{url}” class=“result_{format}”>{title}[/url] - {excerpt} <small>({url})</small>    
  2.   {if count == total_results}

{/if}
      {paginate}
        Page {current_page} of {total_pages} pages {pagination_links}
      {/paginate}
{/exp:google_custom_search:results}
  </div>
</div>
{/exp:stash:set}

Derek Hogue
# 10
Developer
Derek Hogue

There are long-standing issues with using no_results variables within Stash tags unfortunately.

Delaris Dev
# 11
Delaris Dev

No fix I take it?

Thank you again for your outstanding support! 

I apologize for not testing further.  I was in a lobby waiting to go into a meeting when I got your response and put it up quickly.  Got the 500 error and put the old one back up and had to go into the meeting.  I appreciate you looping back around, so that we have the fix.

Regarding the no_results problem, could we not use an else if structure?  If ==1 xys,  if greater than 1 <ol>  else if “Sorry”.

It has been several years since I have worked in EE.  If you don’t have time for this I totally understand.

Derek Hogue
# 12
Developer
Derek Hogue

No worries at all. Try this tip from the Stash docs (but remove the {exp:stash:not_found} tag and place your message there instead).

Delaris Dev
# 13
Delaris Dev

Will do, Thanks!