This question about Topic Markup Language and applications: Answered

Isempty in IF statement to check formfield

Hey folks!

I'm trying to check in my if statement if an existing formfield is empty and if so then display the topic name else the name of the formfield. Not sure if I'm handling isempty the right way. My approaches (please see source in editing mode):

[[$topic][ %IF{"isempty '$formfield(Handelsname)'" then="$topic" else="$formfield(Handelsname)"}% ]]

Tried to define preference setting HANDELSNAME but did not work neither:

[[$topic][ %IF{"isempty '%HANDELSNAME%'" then="$topic" else="$formfield(Handelsname)"}% ]]

Anyone knows if what I'm trying to do is technically possible? The documentation or examples for the isempty command is not that much.

Hope anyone can help me.

-- PaulHahler - 23 Mar 2010

From your example I assume you are using this in a SEARCH query. You can use the FORMFIELD macro to show a string if the field is empty or if the field does not exist.

In a search you need to escape the % and " chars with $percnt and $quot.

For example: updated
format="   * [[$web.$topic][$percntFORMFIELD{$quotExtension$quot topic=$quot$topic$quot default=$quottdefault value=$topic$quot}$percnt]]"

-- ArthurClemens - 23 Mar 2010

Thanks for your fast support, but this is not actually what I was looking for. In the example you gave above is always shown the topic name as default. I want the search to show the fieldname, in your example "extension", and if this field would be empty then I want the search to show the topicname instead of the empty field.

Another question by the way.. the % and " must I always escape when I'm working with another macro?

-- PaulHahler - 24 Mar 2010

I made a small update to Arthur's format line, adding topic= so that the FORMFIELD macro looks in the right topic for the formfield.

Not sure about explaining the macros but I believe that if the FORMFIELD macro in the format line did not have $percnt it would have expanded (executed) before the SEARCH and thus would not be able to use the $topic variable (that comes from the SEARCH result). If there were two macros in the format line then the left macro would expand before the right, unless delayed with $percnt. So $percnt is for delaying execution and $quot (I think you also can write \") is so the outer macro and parameters don't mix up with the nested macro and it's parameters.

See FormattedSearch, the Nested Search for the basics. Also when ready Support/Faq22.

-- LarsEik - 24 Mar 2010

Paul, I think the example does what you need: show the fieldname [...] and if this field would be empty then [...] show the topicname instead of the empty field. The default parameter is read when the fied name is empty.

-- ArthurClemens - 25 Mar 2010

QuestionForm edit

Subject Topic Markup Language and applications
Version Foswiki 1.0.9
Status Answered
Topic revision: r5 - 25 Mar 2010, ArthurClemens - This page was cached on 25 May 2019 - 14:54.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy