Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-06-01 17:13:25

dquirk
Member
Registered: 2005-10-22
Posts: 12

using chh_if_data to display message when no search results

Could someone post an example of how to use chh_if_data to display a “no search results” message?

I’ve read the discussion that’s here, which says to “just wrap it around the if_individual_article txp tag,” but I don’t quite follow and could (hopefully) benefit from an actual example of how someone has implemented this.

Thanks!

Offline

#2 2006-06-01 19:08:05

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: using chh_if_data to display message when no search results

<txp:if_search>

	<txp:chh_if_data>

		<!-- we searched, and there were results -->
		<txp:article />

	<txp:else />

		<!-- we searched and nothing was found -->
		<p>No results found.</p>

	</txp:chh_if_data>

<txp:else />

	<!-- we didn't search for anything -->
	<txp:article />

</txp:if_search>

:)

Offline

#3 2006-06-01 20:18:50

dquirk
Member
Registered: 2005-10-22
Posts: 12

Re: using chh_if_data to display message when no search results

Thanks!

I almost had it right, but I had a q tag before my article tag, which is of course going to return data if a search has been performed.

So, it appears that I can’t display what the user searched for in this manner if I’m using chh_if_data. Is that correct, or is there a way around this?

Offline

#4 2006-06-01 21:28:39

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: using chh_if_data to display message when no search results

Yes you can. I use something like this:
<code>
<txp:article pgonly=1 />
<p>You were looking for: <strong><txp:q /></strong>, <txp:search_result_count />.</p>
<txp:article />
</code>
See for an explanation of the pgonly attribute zem’s article.

Edit: you wouldn’t even need chh_if_data with this, but you could also use it to display different messages for when there are search results or not.

Last edited by els (2006-06-01 21:34:38)

Offline

#5 2006-06-02 22:17:50

dquirk
Member
Registered: 2005-10-22
Posts: 12

Re: using chh_if_data to display message when no search results

Hmm, I’m still having trouble. Even when a search returns no results, the the code below doesn’t display the text after the first else.

<code>
<txp:if_search>
<txp:chh_if_data>
<txp:article pgonly=1 />
<p>You were looking for: <strong><txp:q /></strong>, <txp:search_result_count />.</p>
<txp:article />
<txp:else />
<p>Your search returned no results.</p>
</txp:chh_if_data>
<txp:else />
<txp:if_article_list>
<txp:article status=“sticky” />
</txp:if_article_list>
</txp:if_search>
</code>

Last edited by dquirk (2006-06-02 22:18:55)

Offline

#6 2006-06-03 08:10:22

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: using chh_if_data to display message when no search results

Try this:
<code>
<txp:if_search>
<txp:chh_if_data>
<txp:article pgonly=1 />
<p>You were looking for: <strong><txp:q /></strong>, <txp:search_result_count />.</p>
<txp:article />
<txp:else />
<p>Your search returned no results.</p>
</txp:chh_if_data>
</txp:if_search>
<txp:if_article_list>
<txp:article status=“sticky” />
</txp:if_article_list>
</code>

Offline

#7 2006-06-05 09:52:50

mazso
Member
Registered: 2005-09-29
Posts: 25

Re: using chh_if_data to display message when no search results

There must be no static content after the if-statement.

Do something like this:

<code>
<txp:if_search>
<txp:chh_if_data>
<txp:article form=“search_results” />
<txp:else />
<p>No search results? etc.</p>
</txp:chh_if_data>
</txp:if_search>
</code>

Don’t do this:

<code>
<txp:if_search>
<txp:chh_if_data>
<txp:article form=“search_results” />
<p>No static content here</p>
<txp:else />
<p>No search results? etc.</p>
</txp:chh_if_data>
</txp:if_search>
</code>

form=“search_results” mustn’t contain any static content.

Mazso

Last edited by mazso (2006-06-05 09:59:45)

Offline

#8 2006-06-05 17:49:10

dquirk
Member
Registered: 2005-10-22
Posts: 12

Re: using chh_if_data to display message when no search results

Thanks!

Offline

Board footer

Powered by FluxBB