Search Results displaying HTML code depending on # of result

General ShopSite user discussion

Search Results displaying HTML code depending on # of result

Postby bobthebuilder » Thu Oct 09, 2008 1:14 pm

Is there a way I can output html code based on the number of results found? This is what I want to do:

If search_results = 0:
<td>some text </td>

Else:
<td> some other text</td>

End If

Thanks in advance.
bobthebuilder
 
Posts: 35
Joined: Mon Sep 29, 2008 9:36 am

Postby loren_d_c » Thu Oct 09, 2008 2:18 pm

If you have ShopSite v9.0 or newer this is pretty easy in your custom search template using the SearchResultCount template tag added in that version, see the custom search template spec at:

http://www.shopsite.com/help/9.0/en-US/sc/pro/custom.template.spec-search.html

I've not used this tag personally in a custom search template (so consider this pseudo-code that you will test yourself), but I would imagine you could use this code something like:

[-- IF SearchResultCount "0" --]
No results for the search: [-- SEARCHSTRING --]
[-- ELSE --]
There were [-- SearchResultCount --] results for the search: [-- SEARCHSTRING --]
[-- END_IF --]


If you have an older version of ShopSite, then the only way I know of to get the count by setting a VAR to 0 before the LOOP SEARCH loop and incrementing it in the loop whenever a product result is incountered, then after the END_LOOP SEARCH you can check your VAR, if it is still 0 then there were no results, otherwise there wete results. So perhaps something like this:

[-- VAR.searchresultscounter 0 --]
<table border="1">
[-- LOOP SEARCH --]
[-- IF SEARCHPRODUCT --]
<td>Product:</td>
[-- VAR.searchresultscounter INC --]
[-- END_IF --]
[-- IF SEARCHLINK --]
<td>Link:</td>
[-- END_IF --]
[-- SEARCHRESULT --]
[-- END_LOOP SEARCH --]
</table>

[-- IF VAR.searchresultscounter "0" --]
No results for the search: [-- SEARCHSTRING --]
[-- ELSE --]
There were [-- VAR.searchresultscounter --] results for the search: [-- SEARCHSTRING --]
[-- END_IF --]

-Loren
loren_d_c
 
Posts: 2572
Joined: Fri Aug 04, 2006 12:02 pm
Location: Anywhere

Postby bobthebuilder » Thu Oct 09, 2008 2:54 pm

I'm using ShopSite 9. I tried the following code:

[-- IF SearchResultCount "0" --]
No results for the search: [-- SEARCHSTRING --]
[-- ELSE --]
There were [-- SearchResultCount --] results for the search: [-- SEARCHSTRING --]
[-- END_IF --]

No matter if a product is found or not the code after the Else statement is always printed. Any suggestions? I'm using the classy_se_template with modified html code (mainly wrapping the entire page in my page design. I've left the guts of the template in tact.

-Adam
bobthebuilder
 
Posts: 35
Joined: Mon Sep 29, 2008 9:36 am

Postby loren_d_c » Thu Oct 09, 2008 3:09 pm

Try [-- IF SearchResultCount 0 --] (so remove the doublequotes around the zero).

-Loren
loren_d_c
 
Posts: 2572
Joined: Fri Aug 04, 2006 12:02 pm
Location: Anywhere

Postby bobthebuilder » Thu Oct 09, 2008 3:16 pm

Unfortunately, that didn't make a difference. I'll PM you the template code and hopefully you can see what the problem is.
bobthebuilder
 
Posts: 35
Joined: Mon Sep 29, 2008 9:36 am

Postby loren_d_c » Thu Oct 09, 2008 3:37 pm

Sorry, I don't have time to debug a template, but perhaps it doesn't like the comparison to the number. Try not comparing it to a number and reversing the logic, so perhaps like this:

[-- IF SearchResultCount --]
There were [-- SearchResultCount --] results for the search: [-- SEARCHSTRING --]
[-- ELSE --]
No results for the search: [-- SEARCHSTRING --]
[-- END_IF --]

-Loren
loren_d_c
 
Posts: 2572
Joined: Fri Aug 04, 2006 12:02 pm
Location: Anywhere


Return to User Forum

Who is online

Users browsing this forum: No registered users and 78 guests