Chapter 6. Creating Widgets

In Chapter 5, we walked through the process of creating a content field. In order to be used, our field had to be added to a content type. We couldn’t just add it to a zone in a template and have it appear. For that behavior, we’ll need a widget. Like fields, widgets are a type of Orchard module. In this chapter, we’ll walk through the process of creating a widget that we can attach to all or some pages in our site.

Content Parts

Content parts are reusable pieces of functionality (UI or behavior) that are added to content types. When we created the Event content type, we added the Containable content part to its definition, which allowed events to be contained in projection pages. The Body content part allowed us to include an HTML body in our Bio content type.

Even though a widget is a content type and not a part, creating a widget is effectively the same process as creating a content part. However, we’ll include some additional metadata to make the part behave like a widget and not a part. In other words, once a part becomes a widget we can add it as content in a zone.

In this chapter, we’re going to create a module for embedding videos on our site. At the time of this writing, there exists only a single YouTube module in the Orchard Gallery. That module is a field, which again requires a content type to be defined with that field in order for it to be used with content items. What we want instead is a widget that we can attach to different pages, regardless ...

Get Orchard CMS: Up and Running now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.