SID-00188: How to set variables for a topic hierarchy?
| Status: |
Answered |
TWiki version: |
4.0.4 |
Perl version: |
|
| Category: |
CategoryRendering |
Server OS: |
|
Last update: |
16 years ago |
I'd like to set variables in a topic whose values were propagate to all sub-topics in topic hierarchy. I tried %INCLUDE% including a page with the settings with no success... Is there any way to do that?
--
WeberSotomba - 13 Mar 2009
Discussion and Answer
An INCLUDEd page does not inherit variables.
As a workaround you can use a
SpreadSheetPlugin VarCALC:
$SET() a variable in the INCLUDEd page, and
$GET() the variable in the including page. See working example at
Sandbox.SpreadSheetRollupTest.
--
PeterThoeny - 13 Mar 2009
It worked indeed. I tried another approach using a more regular var setting, like this:
<!--
VAR=0304
-->
It worked but the var "importing" is quite clumsy:
* Set VAR = %<nop>INCLUDE{"SetIncludedVarsSet" pattern=".*?VAR=(\S+).*"}%
There is a more complete example on
SetIncludedVars .
It seems to me that a good solution would be some way to evaluate
Set VAR = <value> statements that would be dynamically created by an %EXTRACT{"SetIncludedVarsSet"}% command.
Obviously I have no clue if it is feasible
--
WeberSotomba - 14 Mar 2009
See also proposed feature to
MakingVarVARTopicCapable.
--
PeterThoeny - 16 Mar 2009
Right, that is a better way of importing a single variable. But to import a bunch of vars, it seems that a good way (if system architecture allows that) would be some kind of routine to evaluate a string in the current topic, alike the Perl
eval() routine. For instance:
%STR_EVAL(" * Set VAR = 0304$n * Set VAR2 = \"This string\"")%
The string could be generated by a
%EXTRACT{}% processing the topic with the var settings.
Is this feasible? This routine would have a number of other uses, I guess.
Tks for your assistance.
--
WeberSotomba - 16 Mar 2009
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.