Many ways to relate Orchard things, part 2: content item picker field

In the first post in this series, we’ve looked at the most difficult way to create relationships in Orchard. In this post, we’ll look at the easiest: content item picker field.

To start using a content item picker field, just head over to the content definitions, edit a content type, and add the field:

Adding a content item picker field to a content type.

Once this is done, you can expand the settings for the field, and configure it:

Configuring a content picker field.

As you can see, you can set the cardinality of the relationship there: you can specify if zero, one, or more related items are permitted. In the bottom textbox, you can specify what related contents are allowed.

Once you’ve saved the content type definition, you can start adding related contents from the content item editor, removing them, or re-ordering them:

Managing related items

The content item picker field makes things really easy. Let's recap...

Pros

  1. Super-easy, no code to write, except for front-end template overrides in the theme.
  2. Allows for more than one relationship per type.

Cons

  1. Only works between content items.
  2. Can’t query on related items except with Projections, or similar techniques.
  3. Can't customize the admin user experience.

Use cases

You can use content picker any time you need to establish relationships between content items, but don’t need to query on the relationship other than using Projections. You also need to be OK with the standard UI that comes with the content picker: it’s going to be that list of items, with the picker popup. You can’t have checkboxes, drop-downs, or type-ahead experiences.

No Comments