From 9319fa6a49a1c6dbf8d3e67945e431b454ab05ff Mon Sep 17 00:00:00 2001 From: ArthurClemens Date: Fri, 30 Jan 2009 20:33:12 +0000 Subject: [PATCH] Item914: added examples for query search with IF git-svn-id: http://svn.foswiki.org/trunk@2249 0b4bb1d4-4e5a-0410-9cc4-b2b747904278 --- core/data/System/IfStatements.txt | 32 +++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/core/data/System/IfStatements.txt b/core/data/System/IfStatements.txt index bb231056f4..d80744388d 100644 --- a/core/data/System/IfStatements.txt +++ b/core/data/System/IfStatements.txt @@ -3,6 +3,9 @@ The =%IF%= construct gives Foswiki the power to include content in topics based on the value of simple expressions. +%TOC% + +---++ Syntax =%IF{"CONDITION" then="THEN" else="ELSE"}%= In the example above, if CONDITION evaluates to TRUE, then THEN will be included in the topic; otherwise ELSE will be included. @@ -21,7 +24,7 @@ The basic syntax of a condition is the same as [[QuerySearch][the syntax used fo | =$= | expands a URL parameter or [[Macros][macro]] name. Plugin handlers *are not called*. You can pass a limited subset of parameters to macros by enclosing the parameter string in single quotes; for example, =$ 'MACRO{value}'=. The ='MACRO{value}'= string may *not* contain quotes (' or "). | | ={X}= | expands to the value of the =configure= setting {X} - for example, ={ScriptUrlPath}= | -*Examples:* +---+++ Examples 1. Macro defined or not @@ -90,7 +93,8 @@ You %IF{"'%USERNAME%' ingroup 'AdminGroup'" then="are an admin" else="are a norm *Configuration items* are defined in [[%SCRIPTURLPATH{"configure"}%][configure]]. You cannot see the value of a configuration item, you can only see if the item is set or not. -*Context identifiers* are used in Foswiki to label various stages of the rendering process. They are especially useful for [[Skins][skin]] authors to find out where they are in the rendering process. The following context identifiers are available: +---++ Context identifiers +Context identifiers are used in Foswiki to label various stages of the rendering process. They are especially useful for [[Skins][skin]] authors to find out where they are in the rendering process. The following context identifiers are available: | *id* | *context* | | =absolute_urls= | Set if absolute URLs are required | | =attach= | in attach script (see CommandAndCGIScripts) | @@ -131,4 +135,28 @@ In addition there is a context identifier for each enabled plugin; for example, The =%IF%= statement is deliberately kept simple. In particular, note that there is no way to conditionally execute a Set statement. If you need more sophisticated control over formatting, then consider using the SpreadSheetPlugin. +---++ Query syntax + Note also that while the [[QuerySearch][query syntax]] can be used to access form fields, there are some contexts in which an IF statement may be used where there is no topic context, or the topic context is not what you expected. + +---+++ Examples +Display the value of a form field if the topic has form field "Summary": + +%FORMFIELD{"%IF{"'%TOPIC%'/Summary" then="Summary"}%"}% + + +Test if the topic has attachments: + +%IF{"'%TOPIC%'/attachments" then="has attachments"}% + + +Test if the topic has an attachment with 'receipt' or 'Receipt' in the name: + +%IF{"'%TOPIC%'/attachments[lc(name)~'*receipt*']" then="has 'receipt' attachment"}% + + +Test if a topic text contains a certain word: + +%IF{"'%SYSTEMWEB%.WebHome'/lc(text)~'*welcome*'" then="contains 'welcome'"}% + +