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
--
RayWadkins - 15 Dec 2008
Answer
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is 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