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
|
Posted: 13 August 2019 03:52 PM |
|
|
|
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
|
Posted: 13 August 2019 05:10 PM |
# 1
|
|
Developer
|
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
|
Posted: 13 August 2019 07:41 PM |
# 2
|
|
|
It took the site down
This page isn’t working coosbay.org is currently unable to handle this request.
HTTP ERROR 500
|
|
|
Derek Hogue
|
Posted: 13 August 2019 09:33 PM |
# 3
|
|
Developer
|
Looking at your site right now, the page (and the keywords) appear to be working?
|
|
|
Delaris Dev
|
Posted: 13 August 2019 10:07 PM |
# 4
|
|
|
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
|
Posted: 14 August 2019 09:16 AM |
# 5
|
|
Developer
|
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
|
Posted: 14 August 2019 09:24 AM |
# 6
|
|
|
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
|
Posted: 14 August 2019 09:40 AM |
# 7
|
|
|
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
|
Posted: 14 August 2019 09:43 AM |
# 8
|
|
Developer
|
Are you nesting the exp:google_custom_search tag within another tag (like a channel:entries tag)?
|
|
|
Delaris Dev
|
Posted: 14 August 2019 09:46 AM |
# 9
|
|
|
{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}
-
{if image}[url=”{url}”]{thumbnail_image}
{/if}
<a href=”{url}” class=“result_{format}”>{title}[/url] - {excerpt} <small>({url})</small>
{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
|
Posted: 14 August 2019 09:50 AM |
# 10
|
|
Developer
|
There are long-standing issues with using no_results variables within Stash tags unfortunately.
|
|
|
Delaris Dev
|
Posted: 14 August 2019 09:58 AM |
# 11
|
|
|
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
|
Posted: 14 August 2019 10:34 AM |
# 12
|
|
Developer
|
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
|
Posted: 14 August 2019 10:35 AM |
# 13
|
|
|
Will do, Thanks!
|
|
|