A ConditionalRenderer or a SwitchRenderer allows you to put a limited
amount of logic directly into your configuration files.
(This may have advantages: In simple cases this may completely avoid having to write
C++ code. Anyhow configuration files are typically much easier
to change than C++ code.)
At runtime both Renderers look up some state in the Context - i.e. in one of the different stores making up the Context - and based on what they find decide which subsequent Renderers to use.
The difference between ConditionalRenderer and SwitchRenderer is that ConditionalRenderer typically chooses among two alternatives - i.e. it acts like a C++ if/else expression - whereas SwitchRenderer may choose from multiple alternatives - i.e. it corresponds to a C++ switch construct.
[[#wd DisplayAnythingRenderer { /AnythingInfo { "/Renderers {" " ...." " /ConditionalRenderer { Condition }" " /SwitchRenderer { Switch }" " ...." "}" } }]]
[[#wd DisplayAnythingRenderer { /AnythingInfo { "{" " /ContextCondition "name"" " /True { Renderer descriptor for TestCondition == True }" " /False { Renderer descriptor for TestCondition == False }" " /Defined { Renderer descriptor for TestCondition == Defined }" " /Undefined { Renderer descriptor for TestCondition == Undefined }" " /Error { Renderer descriptor for TestCondition == Error }" "}" } }]]Of this configuration Anything only the slot ContextCondition is mandatory. It specifies what slot name to use for the lookup in the Context (ContextCondition should therefore usually contain a string).
All the other slots then specify what to do - depending on the value that is
looked up - and may be omited entirely.
(If the value retrieved from the Context is a 'long', it is automatically
interpreted as a Boolean - which is either 'True' or 'False'. Otherwise it
is simply treated as either 'Defined' or 'Undefined'.)
Structure of a Renderer specification as expected by a SwitchRenderer:
[[#wd DisplayAnythingRenderer { /AnythingInfo { "{" " /ContextLookupName "name"" " /Case {" " /xxx { Renderer descriptor for TestCondition == xxx }" " /yyy { Renderer descriptor for TestCondition == yyy }" " }" " /Default { Renderer descriptor for default case }" "}" } }]]The configuration Anything for SwitchRenderer is very similar to the one used by ConditionalRenderer. Since SwitchRenderer does not treat the looked up value as either Boolean or as Defined/Undefined - but always as a String that is then directly used to decide what subsequent Renderer to use - in addition to the slot ContextCondition the configuration data must contain a Case slot that lists all the alternatives that are handled. (The slot "_Empty" handles the special case where the looked up value is empty. If the looked up value does not match any case defined in the Case section, the Renderer specification defined as Default - if present - is used.)
[[#wd DisplayAnythingRenderer { /AnythingInfo { "/DebugOutput {" " /HTML {" " /Template {" " "Diagnostic Output:<br>"" " "[[#wd Lookup myData]]"" " }" " }" "}" } }]]Furthermore you decide that you do not want any debug output in the productive environment and you want to control whether debug output is created by a setting in the main configuration file:
[[#wd DisplayAnythingRenderer { /AnythingInfo { "/ConditionalDebugOutput {" " /Condition {" " /ContextCondition "ShowDebugOutput"" " /True {" " /Lookup {" " /LookupName "DebugOutput"" " }" " }" " /False {} # do nothing.. this slot could be omitted.." " }" "}" } }]]an aequivalent though more compact specification would be:
[[#wd DisplayAnythingRenderer { /AnythingInfo { "/ConditionalDebugOutput {" " /Condition {" " /ContextCondition "ShowDebugOutput"" " /True {" " /HTML {" " /Template {" " "Diagnostic Output:<br>"" " "[[#wd Lookup myData]]"" " }" " }" " }" "}" } }]]
[[#wd DisplayAnythingRenderer { /AnythingInfo { "[[#wd Lookup ConditionalDebugOutput]]" } }]]
[[#wd DisplayAnythingRenderer { /AnythingInfo { "/ShowDebugOutput 1" } }]]You are done.. now you can now enable/disable your debug output simply by setting /ShowDebugOutput in Config.any!
Page, Role, Context, ContextLookupRenderer