Tags:
create new tag
view all tags

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:

Warning: Can't find topic Sandbox.PhotoTest

With SpreadSheetPlugin:

%CALC{$IF($EXACT(1,), Warning: Can't find topic Sandbox.PhotoTest ,)}%

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 Warning: Can't find topic Sandbox.PhotoTest

(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 | Attach | Watch | Print version | History: r9 < r8 < r7 < r6 < r5 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r9 - 2006-01-03 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.