archive_me1Add my vote for this tag create new tag
, view all tags
At the moment it is really hard for plugins to know where their handlers were invoked from. One of the problems this causes is that a plugin which generates active content (e.g. forms and javascript) doesn't know if the context is a view, a preview, an rdiff or a changes. So the plugins have to use rather dodgy methods of trying to determine their context. For example, CommentPlugin does this:
       my $scriptname = $ENV{'SCRIPT_NAME'} || '';
       my $previewing = ($scriptname =~ /\/(preview|gnusave|rdiff)/);

It would be much better to have a reliable way for a plugin to determine what context it is in. Here are some of the context identifiers I would find useful in my various plugins:

Context Comments
active Plain view requiring active content e.g. view, edit
passive Plain view requiring disabled content e.g. preview, rdiff. Mutually exclusive with active.
text Rendering main text body
include Rendering included text
formfield= Rendering form field data
template Rendering template text

(Please add to/modify the table above as appropriate)

The specific proposal is to add:

StaticMethod TWiki::Func::getContext() -> $attrs

  • $attrs - comma-separated list of attributes of the current context.
Determine the context of this handler call. For example, to determine if a form input field should be disabled in the current rendering context, you might write:
my $context = TWiki::Func::getContext();
if( $context =~ /\bpassive\b/ ) {
    $_[0] =~ s/%TAG%/<input disabled="disabled" name="bah" value="BAH" \/>/g;
} elsif( $context =~ /\bactive\b/ ) {
    $_[0] =~ s/%TAG%/<input name="bah" value="BAH" \/>/g;
} else {
    # neither active nor passive, so don't do any changes to the text

Contributors: CrawfordCurrie

No comments or support, so I'm moving this off the Dakar list.

Done in Dakar.

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2006-02-13 - CrawfordCurrie
  • 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-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.