Tags:
create new tag
view all tags

Question

The variable META{"parent" ...} (VarMETA) will generate those nifty breadcrumbs to lead you recursively back up through the parentage.

I need to do that, but instead of the $topic name, I need to use a formfield value from that topic.

I need this because I"m using AUTOINCxxx style topics. Having

 Top > Folder001 > Folder002 
is not nearly as useful as
Top > Human Resources > Department of Firing People

I've played around with using the FormattedSearch arguments (all those nifty ones that start with $) within a format argument to META-parent but whatever set that supports, it doesn't include $formfield.

Environment

TWiki version: TWikiRelease04x01x02
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS: Irix 6.5.28
Web server: Apache 2.2.4
Perl version: 5.8.x
Client OS: Win xp Pro
Web Browser: Firefox 2.x
Categories: Search

-- MatthewKoundakjian - 02 Jul 2007

Answer

ALERT! 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.

I'm investigating AddFormfieldParamToMetaParent as kind of what I was on about... it's a patch to some past version, but it looks like I can make it work. Was hoping for a high-level solution, but a solution is better than none.

-- MatthewKoundakjian - 08 Jul 2007

This is currently not possible. You'd need a TopicDisplayName feature, whgich is porposed but will not be implemented in the upcoming TWiki 4.2 release.

You could try nested searches, but this assumes fixed number of nesting, such as 3 levels. And nested searches are slow.

An alternative is to enhahance META{"parent" ...} to allow arbitrary display of each parent link.

-- PeterThoeny - 08 Jul 2007

Upon brief examination, the TopicDisplayName feature looks like a good approach.

I'm going to poke around in renderParent to see if I can coherently enhance META{"parent"} ...

Thanks.

-- MatthewKoundakjian - 09 Jul 2007

Ok, I got what I wanted done. I had to hack on renderParent in Render.pm and I made a duplicate function to getTopicParent in Store.pm, which I called getTopicField.

getTopicField differs by getTopicParent on the lines with " #####" on them.

hal 163# diff -nbi twiki-4.1.2-orig/lib/TWiki/Store.pm twiki-4.1.2/lib/TWiki/Store.pm
a1448 43
---++ ObjectMethod getTopicField (  $web, $topic, $fieldname  ) -> $string

Get the value of the topic's named fields. Needs to be fast because
of use by Render.pm.

=cut

# SMELL: does not honour access controls

sub getTopicField {  #####
    my( $this, $web, $topic, $fieldname ) = @_;   #####
    ASSERT($this->isa('TWiki::Store')) if DEBUG;
    ASSERT(defined($web)) if DEBUG;
    ASSERT(defined($topic)) if DEBUG;

    return undef unless $this->topicExists( $web, $topic );

    my $handler = $this->_getHandler( $web, $topic );

    my $strm = $handler->getStream();
    my $data = '';
    while( ( my $line = <$strm> ) ) {
        if( $line !~ /^%META:/ ) {
            next;   #####
        } else {
            $data .= $line;
        }
    }
    close( $strm );

    my $meta = new TWiki::Meta( $this->{session}, $web, $topic );
    $this->extractMetaData( $meta, \$data );
    my $parentMeta = $meta->get( 'FIELD', $fieldname );   #####
    return $parentMeta->{value} if $parentMeta;   #####
    return undef;
}

=pod

For changes to renderParent, I am just putting in a diff...

hal 167# diff -nbi twiki-4.1.2-orig/lib/TWiki/Render.pm twiki-4.1.2/lib/TWiki/Render.pm
d124 1
a124 6
    my $formfield =   $ah->{formfield} || '';
        my $format;
    if ($formfield) {
          if ($ah->{format}) { $format = $ah->{format};}
          else               { $format = '[[$web.$topic][$formfield]]';}  }
        else { $format =      $ah->{format} || '[[$web.$topic][$topic]]'; }
a132 1
        my $pTopicFormName;
a145 2
        $pTopicFormName = 
                       $store->getTopicField( $pWeb, $pTopic, $formfield ) || $pTopic;
a150 1
        $text =~ s/\$formfield/$pTopicFormName/g;

I've not tested it exhaustively, but pretty much, it adds a field called "formfield" and allows that to be a part of the format statment (which now can have topic, web and formfield values).

I am now using:

%TMPL:DEF{"breadcrumb"}%%ICON{"arrowbright"}%%META{"parent" formfield="FolderSummary"}%%TMPL:END%

-- MatthewKoundakjian - 09 Jul 2007

Change status to:
Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2007-07-09 - MatthewKoundakjian
 
  • 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.