Taxonomies in Orchard Core CMS

Custom Orchard Core Development

Taxonomies was recently added to Orchard Core. You can add taxonomies to your Orchard Core Website by enabing the Taxonomies Module from the administrator dashboard under Configuration -> Modules. Once enabled, you can create taxonomies and taxonomy terms and associate the taxonomy terms to content types using a Taxonomy Field. In this Orchard Core Tutorial I will use taxonomies to classify movies in my movie library by genres.

Enable Taxonomies

Signin to the Orchard Core CMS Website as an administrator and enable the Taxonomies Module under Configuration -> Modules. Enabling taxonomies will allow you to create a Taxonomy as well as attach a Taxonomy Field to Content Types.

Taxonomies Module Orchard Core CMS

Create Taxonomy Term Type

A taxonomy includes taxonomy terms. These terms need to be associated with a content type. Before creating the taxonomy, we need to create a type that will act as the taxonomy term content type. Since I will be creating a taxonomy, called Genres, and each taxonomy term will represent a genre, I called my taxonomy term content type, Genre. I added a Title Part, since every Genre will need a title (e.g. Action, Adventure, Sci-fi, etc.).

Taxonomy Term Type Orchard Core

Create Taxonomy in Orchard Core

After creating a taxonomy term content type, called Genre, I created a Taxonomy, called Genres, and specified its Term Content Type as Genre. I then added 3 genres: Action, Adventure, and Sci-fi. Note that you can nest taxonomy terms and use drag-and-drop to re-order and nest terms as you see fit.

Taxonomy in Orchard Core CMS

Add Taxonomy Field to Movie Content Type

I want to use the Genres Taxonomy and its terms to help classify my movie library into various genres. To do so, I added a Taxonomy Field, called Genres, to my Movie Content Type. I specified it to use the Genres Taxonomy I just created and made it a required field.

Taxonomy Field Orchard Core

Adding and Editing Movies Using Taxonomies in Orchard Core CMS

When adding and editing movies in my movie library I can specify the genres for each movie using the new Taxonomy Field. By default the Taxonomy Field will be displayed as a list of nested checkboxes when multiple values can be specified.

Content Type with Taxonomy Field Orchard Core CMS

Displaying Taxonomy Terms in Orchard Core CMS

Displaying a movie from my library shows the list of genres (i.e. taxonomy terms) associated with it. I am using a custom Liquid Template in Orchard Core to display the movie along with its taxonomy terms.

Taxonomies Tutorial Orchard Core

GraphQL and GraphiQL in Orchard Core

As I showed in a recent Orchard Core Tutorial, GraphQL in Orchard Core CMS Using GraphiQL, let's view the movie and its genres using GraphiQL and GraphQL.

{
    movie {
        displayText
        images {
            urls
        }
        genres {
            termContentItems {
                displayText
            }
        }
        markdownBody {
            html
        }
        autoroute {
            path
        }
    }
}

The results of the query are as follows.

{
  "data": {
    "movie": [
      {
        "displayText": "Raiders of the Lost Ark",
        "images": {
          "urls": [
            "/media/raiders-of-the-lost-ark.jpg"
          ]
        },
        "genres": {
          "termContentItems": [
            {
              "displayText": "Action"
            },
            {
              "displayText": "Adventure"
            }
          ]
        },
        "markdownBody": {
          "html": "<p>In 1936, archaeologist and adventurer...</p>\n"
        },
        "autoroute": {
          "path": "movies/raiders-of-the-lost-ark"
        }
      }
    ]
  }
}

Conclusion

Taxonomies was just released in Orchard Core CMS and still has a few more features that need to be added, but it looks really good and certainly worth taking for a spin. Recipe Migrations was also added to Orchard Core and is worth learning as well.