Segments & Search
Posted: 22 July 2006 05:22 PM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1521
Joined  05-15-2004

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.

 Signature 


:: Westeros :: Hippoi Athanatoi ::

Blackadder: “Baldrick, have you no idea what irony is?”   
Baldrick: “Yeah! It’s like goldy and bronzy, only it’s made of iron.”
Blackadder III, Amy and Amiability

Profile
 
 
Posted: 23 July 2006 01:42 AM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  16215
Joined  05-15-2004

I have tried that before, and couldn’t make it work, don’t know why. Better luck to you grin

 Signature 

Everything will be good in the end. If it’s not good, it’s not the end.

Profile
MSG
 
 
Posted: 23 July 2006 01:46 AM   [ Ignore ]   [ # 2 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1521
Joined  05-15-2004

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. smile

 Signature 


:: Westeros :: Hippoi Athanatoi ::

Blackadder: “Baldrick, have you no idea what irony is?”   
Baldrick: “Yeah! It’s like goldy and bronzy, only it’s made of iron.”
Blackadder III, Amy and Amiability

Profile
 
 
Posted: 23 July 2006 07:23 AM   [ Ignore ]   [ # 3 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23755
Joined  05-20-2002

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.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 23 July 2006 07:25 AM   [ Ignore ]   [ # 4 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  16399
Joined  06-03-2002

if:else turns it into an advanced conditional, and is then parsed very late in the game.  You will probably find success doing:

{if segment_3 = "Results"}
  results code
{
/if}

{if segment_3
!= "Results"}
  search code
{
/if}

 Signature 
Profile
MSG
 
 
Posted: 23 July 2006 08:01 AM   [ Ignore ]   [ # 5 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1521
Joined  05-15-2004

Derek,

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. smile

 Signature 


:: Westeros :: Hippoi Athanatoi ::

Blackadder: “Baldrick, have you no idea what irony is?”   
Baldrick: “Yeah! It’s like goldy and bronzy, only it’s made of iron.”
Blackadder III, Amy and Amiability

Profile
 
 
Posted: 23 July 2006 08:04 AM   [ Ignore ]   [ # 6 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  16399
Joined  06-03-2002

Alright, plan b, using php segment conditionals.  (Input parsing) wink

<?php
global $IN;

if (
$IN->SEGS[3] == "Results"): ?>

  
...results code...

<? else: ?>

  
...search code...

<? endif; ?>

 Signature 
Profile
MSG
 
 
Posted: 23 July 2006 08:08 AM   [ Ignore ]   [ # 7 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1521
Joined  05-15-2004

I switched the parsing to php on input (I was using on output), but with the php conditionals I get the following error:

Parse error: syntax error, unexpected ‘;’, expecting ‘(’ in /path/ExpressionEngine/valyria/core/core.functions.php(570) : eval()‘d code on line 78

 Signature 


:: Westeros :: Hippoi Athanatoi ::

Blackadder: “Baldrick, have you no idea what irony is?”   
Baldrick: “Yeah! It’s like goldy and bronzy, only it’s made of iron.”
Blackadder III, Amy and Amiability

Profile
 
 
Posted: 23 July 2006 12:18 PM   [ Ignore ]   [ # 8 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23755
Joined  05-20-2002

It needs a : after the elseif- or maybe just make that an else.  The below tested out ok:

<?php
global $IN;

if (isset(
$IN->SEGS[3]) AND  $IN->SEGS[3] == "Results") : ?>

  
...results code...

<?php else: ?>

  
...search code...

<?php endif; ?>

ETA- was running into problems without the isset check.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 23 July 2006 12:35 PM   [ Ignore ]   [ # 9 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1521
Joined  05-15-2004

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.

 Signature 


:: Westeros :: Hippoi Athanatoi ::

Blackadder: “Baldrick, have you no idea what irony is?”   
Baldrick: “Yeah! It’s like goldy and bronzy, only it’s made of iron.”
Blackadder III, Amy and Amiability

Profile
 
 
Posted: 23 July 2006 01:00 PM   [ Ignore ]   [ # 10 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23755
Joined  05-20-2002

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.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 23 July 2006 01:13 PM   [ Ignore ]   [ # 11 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  16399
Joined  06-03-2002

Yep sorry for the syntax bits.  Posting before a shower and coffee is a bad idea.

 Signature 
Profile
MSG
 
 
Posted: 23 July 2006 01:15 PM   [ Ignore ]   [ # 12 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23755
Joined  05-20-2002

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.

Make sense?  It did work for me this way.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 23 July 2006 01:22 PM   [ Ignore ]   [ # 13 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1521
Joined  05-15-2004

Ahh, taking out the ‘Results’ segment seems to have done the trick (and the modified code fixed the php error). Thanks. smile

I was thinking of using pagination, though. What sort of modifications would that need?

 Signature 


:: Westeros :: Hippoi Athanatoi ::

Blackadder: “Baldrick, have you no idea what irony is?”   
Baldrick: “Yeah! It’s like goldy and bronzy, only it’s made of iron.”
Blackadder III, Amy and Amiability

Profile
 
 
Posted: 23 July 2006 01:47 PM   [ Ignore ]   [ # 14 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23755
Joined  05-20-2002

Heh- none.  I wasn’t thinking- and once I did, can’t see why it should matter.  But if it does, give a yell.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 23 July 2006 01:47 PM   [ Ignore ]   [ # 15 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1521
Joined  05-15-2004

Oh, okay. smile

Thanks a lot for all the help. smile

 Signature 


:: Westeros :: Hippoi Athanatoi ::

Blackadder: “Baldrick, have you no idea what irony is?”   
Baldrick: “Yeah! It’s like goldy and bronzy, only it’s made of iron.”
Blackadder III, Amy and Amiability

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 66519 Total Logged-in Users: 24
Total Topics: 84971 Total Anonymous Users: 15
Total Replies: 455843 Total Guests: 143
Total Posts: 540814    
Members ( View Memberlist )