This question about Topic Markup Language and applications: Answered

IF defined gives different result in INCLUDE with Set vs

  • Set NOWYSIWYG = 1
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

  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:

DisplayTestDefinedIncludeOne.JPG

Part 2

  1. 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:
DisplayTestIncludeDefinedTwo.JPG

The result shows that
  1. THEWEB is not defined in in topic TestIncludeDefinedTwo,
  2. 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" ...}%
DisplaySet.JPG DisplayVarSET.JPG

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
 

QuestionForm edit

Subject Topic Markup Language and applications
Extension
Version Foswiki 2.0.3
Status Answered
Related Topics
I Attachment Action Size Date Who Comment
DisplaySet.JPGJPG DisplaySet.JPG manage 12 K 09 Jan 2016 - 11:21 BramVanOosterhout  
DisplayTestDefinedIncludeOne.JPGJPG DisplayTestDefinedIncludeOne.JPG manage 19 K 08 Jan 2016 - 13:38 BramVanOosterhout  
DisplayTestIncludeDefinedTwo.JPGJPG DisplayTestIncludeDefinedTwo.JPG manage 18 K 08 Jan 2016 - 13:39 BramVanOosterhout  
DisplayVarSET.JPGJPG DisplayVarSET.JPG manage 11 K 09 Jan 2016 - 11:22 BramVanOosterhout  
Topic revision: r3 - 09 Jan 2016, BramVanOosterhout
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