Using one's own variables in INCLUDE

Q: I am trying to use variables in an included topic by defining them and using them, but they appear not to work at all, e.g.

   * Set MTJA1 = first value
just produces %MTJA1% when the above is included in another topic rather than the value first value I thought I set to it.

A: It seems to be the case that no new user variables can be defined when topic is being included using %INCLUDE%. The constructions for defining user variables which work when the topic is being displayed directly simply do not work when the topic is included. But, if the variables are defined in the BASETOPIC, then they are accessible in the included text, and the variables have the values they got in the including topic. See an example KimmoKoskenniemiIncluder.

Note that the declaration and the setting of the value of a user variable is done before anything is displayed. One may refer to the value even above the line where the variable is declared.

(Apparently the TWiki parses these variables before it starts to display anything, and includes are part of the displaying. Thus any Set constructions are ineffective when the included topic is displayed.)

Note that the definitions (three spaces * space Set = ...) can be enclosed in XML comment indicators <!-- and --> which makes them invisible but not ineffective.

-- KimmoKoskenniemi - 06 Nov 2007

Topic revision: r2 - 2007-11-06 - KimmoKoskenniemi
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback