Orchard Content Type Widget Layer Rule

Orchard Content Type Widget Layer Rule

There is a new Content Type Layer Rule in Orchard CMS that allows you to add widgets when a specific content type is displayed in Detail View. This type of Orchard Layer Rule is perfect when you want a widget to be displayed only when a page, blog post, product, or other content type is displayed in your Orchard website. This new widget layer rule is available in the Orchard 1.x source code now, or you can download it as part of Orchard 1.7 when it is released. Here is a quick Orchard CMS Tutorial on how it works.

Content Type Layer Rule

For experienced Orchard Web Developers a picture will explain it all, so below is a screenshot of configuring the Content Type Layer Rule in Orchard CMS. In this case, I am configuring a Layer Rule so that widgets in the Blog Post Layer only display when a Blog Post is displayed in Detail. The name of the Content Type, "BlogPost," is case sensitive at this moment. This may change when the feature is released as part of Orchard 1.7.

Content Type Layer Rule for Widgets in Orchard CMS

Prior to this rule, most Orchard Developers would recommend you either create a url rule that targets just blog posts or attach a content part to the BlogPost Content Type, but using the new Content Type Layer Rule is much, much easier. Now I can easily add a social widget, for example, to all blog posts allowing you to easily find me on Twitter, Google+, Pinterest, Facebook, Dribble, or other social networking site.

I am using this new rule, for example, in my Orchard e-commerce training example to display a marketing callout to Save XX% off throughout the online store using a coupon code when a Content Type of Product is displayed. The examples are endless.

Source Code

You can find the original source code written by Sebastien Ros for this feature on CodePlex. I wanted to use this layer rule in Orchard 1.6 so I extracted the code and created a standalone custom module. You can find the source code on GitHub and the module in the Orchard Gallery.

Conclusion

I hope this Orchard Tutorial helps you while developing your Orchard CMS Websites. Contact me if you would like to hire me for your next Orchard project.

Other features coming in Orchard CMS 1.7 include: