r9 - 03 Jan 2006 - 08:40:13 - PeterThoenyYou are here: TWiki >  Codev Web > StrategyToConditionallyIncludeTopic
Tags:
, create new tag

Implemented: Handle INCLUDE after Plugin handling

It was not possible to conditionally include a topic based on a SpreadSheetPlugin formula. This is now possible because TWiki::handleCommonTags() does an extra call to handleIncludeFile() after the Plugin callback.

This change makes the variable tag expansion consistent:

  • Before Plugin callback:
    • handle preferences
    • handle internal tags
    • handle includes
  • Plugin callback
  • After Plugin callback:
    • handle preferences
    • handle internal tags
    • handle includes (NEW)
  • handle TOC

Contributors:
-- ArthurClemens - 21 Sep 2004
-- PeterThoeny - 25 Sep 2004

Discussions

Stategy to conditionally include a topic

I have been trying to get this construct to work:

if (condition) then INCLUDE

I have tried this with SpreadSheetPlugin, but this does not work. This is the reason I post this on Codev and not in Support - I think there is a definite need for it.

Here are some trials, feel free to improve:

Normal include:

A beautiful picture from the Sandbox web

With SpreadSheetPlugin:

%CALC{$IF($EXACT(1,), A beautiful picture from the Sandbox web ,)}%

Try 2, with $per: (will render nothing)

Perhaps SpreadSheetPlugin is not suited for this, but what is? ConditionalPlugin?

-- ArthurClemens - 20 Sep 2004

Arthur, I think FailedIncludeWarning may be what you want.

-- SamHasler - 20 Sep 2004

I don't know how that can help me.

-- ArthurClemens - 21 Sep 2004

You are on the right track by deferring the execution of the INCLUDE to after CALC. However, I discovered an inconsistency by reading the code in TWikiDotPm's handleCommonTags: All internal variables get expanded after the Plugin hook, except for INCLUDE. This can be fixed by adding the red text:

    &TWiki::Prefs::handlePreferencesTags( $text );
    handleInternalTags( $text, $theTopic, $theWeb );

    # recursively process multiple embedded 



    Warning: Can't find topic ""."" 

 statements and prefs
    $text =~ s/%INCLUDE{(.*?)}%/&handleIncludeFile($1, $theTopic, $theWeb, \@verbatim, @theProcessedTopics )/ge;

    # TWiki Plugin Hook
    &TWiki::Plugins::commonTagsHandler( $text, $theTopic, $theWeb, 0 );

    # handle tags again because of plugin hook
    &TWiki::Prefs::handlePreferencesTags( $text );
    handleInternalTags( $text, $theTopic, $theWeb ); 
    $text =~ s/%INCLUDE{(.*?)}%/&handleIncludeFile($1, $theTopic, $theWeb, \@verbatim, @theProcessedTopics )/ge; 

    $text =~ s/%TOC{([^}]*)}%/&handleToc($text,$theTopic,$theWeb,$1)/ge;
    $text =~ s/%TOC%/&handleToc($text,$theTopic,$theWeb,"")/ge;

I will add this to the code if there are no voices against it.

After adding the line you can write this:
%CALC{$IF($EXACT(1,), condition_is_true, condition_is_false $NOP(%)INCLUDE{Sandbox.PhotoTest}$NOP(%))}%

To get this:
condition_is_false A beautiful picture from the Sandbox web

(I patched TWiki.org to demo this. SVN is pending)

-- PeterThoeny - 21 Sep 2004

This is now implemented and in SVN.

-- PeterThoeny - 25 Sep 2004

 
Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r9 < r8 < r7 < r6 < r5 | More topic actions
Codev.StrategyToConditionallyIncludeTopic moved from Codev.StategyToConditionallyIncludeTopic on 25 Sep 2004 - 09:14 by PeterThoeny - put it back
 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback SourceForge.net Logo