Tags:
create new tag
, view all tags

Question

I am trying to create a plugin that needs to store meta data from a topic.

I have used $meta->find() to get some meta data from a topic. This returns an array of hashes for each entry. I have then modified the data and am looking to put it back into the topic. Looking at TWikiMetaDotPm, it seems that $meta->putAll would work, however I get the following error:

No such pseudo-hash field "name"

I know I could use putKeyed, but the meta data does not have a name attribute. Also, putAll is supposed to be the logical inverse of find, so I did not expect there to be a problem using it.

Any ideas?

Cheers.

Environment

TWiki version: TWikiRelease04x00x00
TWiki plugins:  
Server OS:  
Web server:  
Perl version: 5.8.5
Client OS:  
Web Browser:  
Categories: Plugins

-- AndrewRJones - 24 Jan 2007

Answer

ALERT! If you answer a question - or have a question you asked answered by someone - please remember to edit the page and set the status to answered. The status is in a drop-down list below the edit box.

Plugins can add meta data content to topics, but this can be a bit a slippery slope since the API is not totally baked yet. In any case, meta data that TWiki does not understand survives an edit/save cycle just fine.

Historically, you would append %META variables directly to the text in the beforeSaveHandler callback. It is now recommended to use the meta data object that is passed as a parameter to the beforeSaveHandler.

See TWikiMetaDotPm. There are two types of meta data. Those that are unique ("unkeyed types"), and those that may have multiple entries of same type ("keyed").

Example of "unkeyed type":
META:FORM{name="BasicForm"}

  • Get data: my %form = $meta->findOne( "FORM" );
  • Set data: $meta->put( "FORM", %args );
    %args has key="value" pairs, must contain a name key

Example of "keyed type":
META:FIELD{name="TopicClassification" attributes="" title="TopicClassification" value="TWikiAdvocacy"}
META:FIELD{name="TopicSummary" attributes="" title="TopicSummary" value=""}

  • Get single entry: my %form = $meta->findOne( "FIELD", "TopicClassification" );
  • Set single entry: $meta->put( "FIELD", %args );
    %args has key="value" pairs, must contain a name key, such as ( "name" => $name, "title" => $name, "value" => $value )
  • Get all entries:
    my @fields = $meta->find( "FIELD" );
    foreach my $field ( @fields ) {
       my $name  = $field->{"name"};
       my $value = $field->{"value"};
       # do something
    }

Don't use FORM and FIELD, they are reserved meta data of TWiki, used here just for illustration purposes.

-- PeterThoeny - 24 Jan 2007

 
Change status to:
Topic revision: r3 - 2007-02-17 - PeterThoeny
 
Twitter Delicious Facebook Digg Google Bookmarks E-mail LinkedIn Reddit StumbleUpon    
  • Download TWiki
TWiki logo Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.