Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-11-22 00:32:41

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,453
Website GitHub

use if_search_results properly

I know this has been covered, I just want to clarify something. I have a normal if_search thingamy, viz:

<txp:if_search>
   <txp:article limit="10" searchform="searcho" />
<txp:else />
   <txp:article limit="1" form="blocko" />
</txp:if_search>

It works fine (I’ve omitted the nav stuff for clarity). Then I tried to be clever and did this:

<txp:if_search>
   <txp:if_search_results>
      <txp:article limit="10" searchform="searcho" />
   <txp:else />
     <p>Sorry, no results matched your search for '<txp:search_term />'.</p>
   </txp:if_search_results>
<txp:else />
   <txp:article limit="1" form="blocko" />
</txp:if_search>

But always get the “Sorry…” message displayed, even if there are hits. Further I get the TXP Notice about “Page template … does not contain a txp:article tag”.

*head scratch*

If I add a “fake” article call <txp:article pgonly="1" limit="10" /> straight after <txp:if_search> and before <txp:if_search_results> the page renders without error, the searcho form is called and the results displayed.

So we have to “prime” the article list by calling <txp:article /> and can’t just use the tag inside the if_search_results tag the way I expect. EDIT: I know the official answers from the other threads by jm et al, is that the article tag performs the search, it just seems confusing for thickos like me to have a tag that can’t be used for detecting a search result until after you’ve done a search, thrown it away and then have to do it again to display the results. Is there no other way to do it in a more efficient manner? Or some other way I can lay out the page to get the same effect? Maybe there is no answer and the reason is simply “that’s the way it is” :-\

As a token of my appreciation I’ll update the textbook tag entry to reflect the learned knowledge and hopefully stop someone else tripping up on this — likely elementary — mistake. Sorry for being a bozo.

EDIT2: Textbook updated to reflect how it works now. If anybody can chime in with alternative examples of how to achieve something similar without the pgonly rigmarole, I’ll add it to Textbook as well.

Last edited by Bloke (2008-11-22 01:16:18)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#2 2008-11-22 01:09:38

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: use if_search_results properly

You need a call to the article tag to produce results prior to the if_search_results tag check to return true for that. if_search, I would expect, wouldn’t require that the same way. if_search_results actually needs results to calculate “min” & “max” settings, so I’m guessing greater than 0 would be a default.

Yes, $thispage[‘grand_total’] has to be set for this tag to return true, which would require some article count at least.

Last edited by rsilletti (2008-11-22 01:23:16)

Offline

#3 2008-11-22 01:20:24

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,453
Website GitHub

Re: use if_search_results properly

rsilletti wrote:

if_search, I would expect, wouldn’t require that the same way.

Makes sense, yeah. I guess <txp:if_search /> just checks if the ?q= var has anything in it at all.

Having to do the article call twice just seems kludgy to me, and screams to be optimized. No idea how, but I’m not the brains of this operation!


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2008-11-22 01:25:58

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: use if_search_results properly

Might look at a different way to evaluate than actual articles counted, but I think that would put you back to using GET and pretext values – it does seem a bit klunky.

Offline

#5 2008-11-22 10:56:16

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: use if_search_results properly

Before using txp:if_search_results call txp:article pgonly="1"
Otherway txp doesn’t have an array with search_results, because firstly you check what was found and only after this you call the tag txp:article which makes the search.


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

Board footer

Powered by FluxBB