Tagging your content using custom content types

by Brian Gershon last modified Dec 30, 2008 03:03 PM

Tagging is a nice way of connecting content within your Plone site (and outside of your Plone site too). Here's how to add this functionality to your own content-types and place the associated field in their main edit page.

Plone has a built-in mechanism for tagging content-types called Keywords. When editing standard Plone content, you’ll find Keywords on the “properties” tab.

You can also add this field to your own new Archetype content-types by adding a “subject” field like this:

LinesField(
        name='subject',
        widget=KeywordWidget(
            label="Keywords", 
            label_msgid='myconent_label_subject',
            i18n_domain=' myconent ',
        ),
        accessor="Subject",
        searchable=True,
        multiValued=1
    ),
Or if you’re generating your content via ArchGenXML (see ArchGenXML Introduction), add a field called “subject” of the “lines” type, and make sure you use these tagged values

(screenshot of tagged values for “subject” field in ArgoUML):

Keyword UML Tagged Values

 

Moving the Keyword field for existing content types

For some content-types, Keywords should be front-and-center and not out-of-sight in the Properties tab. If you're creating your own content-type, you just need to add the field as explained above and you're done.

If you'd like to modify an existing content-type (e.g. create a ConferenceNewsItem based on NewsItem):

  1. Using ArgoUML, you can "subclass" the default content-types. See How to subclass an ATContentType in 7 Minutes
  2. In the generated Archetype code, you'll see the "###code-section after-schema". Just modify the schema by adding code in that section (so that regenerating the type won't overwrite).
##code-section after-schema #fill in your manual code here

# move subject field to main form (default schemata), and put it after the existing 'text' field
ConferenceNewsItem_schema['subject'].schemata='default'
ConferenceNewsItem_schema.moveField('subject', after='text')

##/code-section after-schema

This will place the "subject" field after the "text" one in the main edit page of your content type. See Reorder Schema Fields for further information about schema fields reordering.

Further Thoughts - Connecting with External Web 2.0 Services

Now that you've tagged your Plone content, you can use those same tags to pull in data from external Web 2.0 services - such as blogs from Technorati, products from eBay, images from Flickr, etc. For an example, see Mashups in Plone: Leveraging Web 2.0

 

Related