I’ve been trying to combine my advanced search template and my search results template, with the intent of having the latter accessed when a ‘Results’ segment is tacked onto the ‘Search’ template, but I seem to be running into some trouble.
I tried this:
{if segment_3 == “Results”}
Results Code
{if:else}
Search Code
{/if}
However, when I try http://www.domain.com/index.php/Index/Search/, I get the message that no results were found, so it clearly seems to be processing the Results Code instead of the Search Code.
That is very curious, but it does look like I am getting the same result no matter how I try to put the conditionals together. Something about the parsing order for the search results tag, perhaps? Annoying, anyhow.
Mm- might try using embeds? So put the full contents of the tags in two different templates- do the embeds conditionally. If that doesn’t work, might try php parsed on input? Just brainstorms, as I can’t see why it wouldn’t work as you’re approaching it. But if it’s parsed regardless, a php conditional on input would, I think, work.
Just tested that out (both with the results code first and the search code first), but accessing the Search template still gives me the no search results message.
rob1,
I might try the embeds a bit later, I think that could work, though the point of this was partially to get one less template to keep track off.
That gets closer. The search form is generated, but at the top I get this error:
Notice: Undefined offset: 3 in /path/ExpressionEngine/valyria/core/core.functions.php(570) : eval()‘d code on line 61
More troublesome, however, is that I cannot get any search to return a result when I am using the php conditionals. To make sure I have the search form and results page setup correctly, I have tested them separately, and then exactly the same code does return the expected search results.
Hm- I’ll test it out with the search form bits- did you add the isset in there? I added it late to my code- should take care of that undefined offset error.
OK- ignoring the php issues- it looks like the search doesn’t like it if you feed a segment prior to the hash that occurs with a search. But- I’m not sure why you’d need to tack on a ‘results’ segment anyway. If anything is in segment 3, it should be a search hash- right? So, just don’t add the extra segment and code it like:
if (isset($IN->SEGS[3])) : ?>
Then- if anything is in segment three, it serves up search results, otherwise it serves up the search form. If you allow pagination, it would need to be modified a wee bit to take that into account.