This question about Topic Markup Language and applications: Answered
IF defined gives different result in INCLUDE with Set vs
I observe behaviour I do not expect when including a topic with an
IF{ defined... statement. The issue is demonstrated as follows:
*Note: The example is implemented in the Sandbox.
Part 1
- Create a topic BvOIncludeDefinedOne with the following content:
* Set THEWEB = thedefinedweb
%STARTSECTION{"section1"}%
%IF{ "defined THEWEB" then="THEWEB is defined as (%THEWEB%)" else="THEWEB is not defined"}%
%ENDSECTION{"section1"}%
This page displays as:
Part 2
- Create a second topic BvOIncludeDefinedTwo with the following content
- This topic includes the section in BvOIncludeDefinedOne, but NOT the Set statement.
%IF{ "defined THEWEB" then="THEWEB is defined as (%THEWEB%)" else="THEWEB is not defined"}%
*INCLUDE:* %INCLUDE{"BvOIncludeDefinedOne" section="section1"}%
*DBCALL:* %DBCALL{"BvOIncludeDefinedOne" section="section1"}%
This page displays as:
The result shows that
- THEWEB is not defined in in topic TestIncludeDefinedTwo,
- but it is defined in the included text as %THEWEB%.
Question: is that expected behaviour?
When I remove the definition of THEWEB from BvOIncludeDefinedOne, THEWEB is included as undefined, so the issue is easily avoided. But is it meant to be like this? Is there a better way to implement the desired behaviour? (Ie THEWEB is not defined in the included section in TestIncludeDefinedTwo
--
BramVanOosterhout - 08 Jan 2016
This is working as designed. Preferences are set only in the base topic, never in an included topic. When the base topic is first loaded by Foswiki, the preferences are built in memory using the preferences hierarchy: System.DefaultPreferences, Main.SitePreferences, Main.UserTopic, [web].WebPreferences. and finally [web].Topic. Includes are never considered.
Foswiki 2.0 added a new
%SET{}% macro which can set preferences during macro expansion, so you could use =%SET{THEWEB, somevalue}%
and it would override the setting following the default macro expansion order. See
VarSET
--
GeorgeClark - 08 Jan 2016
Thanks for the prompt response George. I have replaced The
Set THEWEB in
BvOIncludeDefinedOne with
%SET{}% in
BvOIncludeDefinedVarSETOne.
* #Set THEWEB = thedefinedweb
* %SET{"THEWEB" value="SETthedefinedweb"}%
%STARTSECTION{"section1"}%
%IF{ "defined THEWEB" then="THEWEB is defined as (%THEWEB%)" else="THEWEB is not defined"}%
%ENDSECTION{"section1"}%
When I include BvOIncludeDefinedVarSETOne in
BvOIncludeDefinedVarSETTwo, the result is as expected. THEWEB in BvOIncludeDefinedVarSETTwo remains undefined.
Set THEWEB |
%SET{"THEWEB" ...}% |
|
|
The behaviourof
%SET{}%
is what I expected for
Set
. Bu clearly, the semantics are different! Thanks again for your prompt assistance. I have changed the title to describe the topic better.
--
BramVanOosterhout - 09 Jan 2016