Tags:
create new tag
, view all tags

Question

I'm trying to put an "IF" statement into the Format of a Search. But the nesting of quotes is messing it up. How is this achieved, if at all. The sample I'm starting with is:

%SEARCH{"name ~ 'Answer?????' and parent.name = '%TOPIC%'" web="%WEB%" type="query" topicexclude="AnswerForm, AnswerTemplate" format="<hr \>%IF{'$formfield(Accepted) = "Yes"' then='---+++ Accepted Answer<br />' else='Not accepted<br />'}%$formfield('Answer')<br \>--[[$formfield('Username')]]<BR>$formfield(Accepted)[[%SCRIPTURLPATH{edit}%/%WEB%/$topic?action=form;redirectto=%TOPIC%][Edit Answer]]" nosummary="on" nosearch="on" nototal="on"}%

Environment

TWiki version: TWikiRelease04x02x03
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS: ed Hat Enterprise Linux Server release 5.2 kernel 2.6.18-92.1.18.el5
Web server: Apache/2.2.3
Perl version: 5.10.0
Client OS: Windows XP Version 2002 SP3
Web Browser: Firefox 3.0.4
Categories: Search

-- RayWadkins - 15 Dec 2008

Answer

ALERT! If you answer a question - or have a question you asked answered by someone - please remember to edit the page and set the status to answered. The status is in a drop-down list below the edit box.

You need to escape the IF so that it fires off once per hit, not once before running the search. Also, you need to escape double quotes. Something like this:

format="<hr \>$percntIF{\"'$formfield(Accepted)' = 'Yes'\" then=\"---+++ Accepted Answer<br />\" else=\"Not accepted<br />\"}$percnt e.t.c....

See also VarSEARCH, FormattedSearch, VarIF.

-- PeterThoeny - 15 Dec 2008

Thanks for the answer, that got me closer, but I'm still struggling. And I think it has to do with the concept of when the $formfield(Accepted) is getting evaluated. I'm seeing 2 results from the search, the first is evaluating to false, not sure why, the second is showing this error:

IF{ " = \"Yes\"" else="Not accepted " then="---+++ Accepted Answer " }: Excess operators (=) in ' = "Yes"'

-- RayWadkins - 15 Dec 2008

I updated my example above: Switched single quotes / double quotes, and put the form field value into single quotes to compare a string with another string. Try again.

-- PeterThoeny - 15 Dec 2008

Thanks for the help, that fixed it. Are there any docs on the complexity of TWiki Variables in TWiki Variables. Cause this isn't the first time I've run into this.

-- RayWadkins - 16 Dec 2008

Please feel free to update TWikiVariables for the benefit of the TWiki community.

-- PeterThoeny - 16 Dec 2008

 
Change status to:
Topic revision: r7 - 2009-01-26 - PeterThoeny
 
Twitter Delicious Facebook Digg Google Bookmarks E-mail LinkedIn Reddit StumbleUpon    
  • Download TWiki
TWiki logo Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.