Movable Type Documentation > Developer

Using the Taggable Interface

Movable Type comes with an easy to tagging framework that allows any developer to attach tags to any object in the system. Once an object is designated as "taggable" then they will immediate be able to use all of the interface methods of a taggable object to get and set tags on that object.

Taggable Interface

The following methods are supported on any taggable object:

  • tags - gets or sets an object's list of tags. If used as a set operation, this method will replace any existing tags with the ARRAY of provided tags.
  • add_tags - takes as input an ARRAY of tags to append to an object
  • remove_tags - removes any tags found in the ARRAY of tags provided to the method as inpput
  • has_tag - returns true if the specified tag can be found in the associated object
  • tag_count- returns the number of tags this object has
  • tagged_count - returns the number of objects that share the specified tag

Inheriting from the Taggable Interface

To make an object taggable, a developer need only state that their package inherits from the MT::Taggable interface.

 package My::Object::Model;
 use MT::Tag;
 use base qw( MT::Object MT::Taggable );

 __PACKAGE__->install_properties({
     # ...
 });

 1;

Using the MT::Taggable Interface

Then you get the methods in the Taggable interface on your model objects:

 sub tag_awesomely {
     my ($m_id) = @_;
     my $m = My::Object::Model->load($m_id);

     if (!$m->has_tags('awesome')) {
         $m->add_tags('awesome');
     }

     $m->save();  # tags are automatically saved by the
                  # MT::Taggable::post_save_tags callback

 }

See Also

This page was last updated on 2008-04-15, 10:01.  

Submit a User Contributed Note

User contributed notes are a great way to share the knowledge you have gained in using Movable Type.

If you have a technical question or problem, please visit Movable Type Support.

(If you haven't left a note here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)