Orchard Posts

Serving up Orchard Content Using Web API

Web Services seem to be all the rage right now, and for good reason – they are easy to work with if architected correctly and can interface with a huge range of platforms, which is very important nowadays.  Web API is Microsoft’s most recent effort at a light weight service platform, at least for HTTP based services, and I really enjoy working with it.

Orchard has historically done a great job of keeping up with the latest and greatest, and now supports full Web API integration.  This is actually a really powerful feature of that platform that I don’t see a lot of people using for whatever reason.  You can serve up literally any piece of content from Orchard as JSON through the Web API, so let’s take a look at how this works.  There are other examples out there on this topic, but I have found most of them to be very trivial in nature and don’t provide any kind of useful example.

This isn’t an in depth tutorial on Web API, it’s assumed you have at least a basic understanding of how it works but I’ll try to cover the main points to get you up and running.

Including Javascript and CSS files on Orchard Admin pages

Recently while working on an Orchard module I needed to include some script and CSS files on a custom admin page.  I initially searched Google to see how to do this but the documentation/information out there seemed a little sparse.   I ended up just digging into other modules that used similar admin pages to see how they did it.  I thought I’d share my findings – it’s not that complicated but hopefully this post will save you a few minutes of searching or troubleshooting.  This method should also work for public facing pages as well.

To include scripts or styles from your plugin, add a ResourceManifest.cs class to the root of your module project.  Inside this plugin you define the scripts and styles you need.  In my case it was as simple as this:

Orchard 1.8.1 released!

Orchard 1.8.1 was released today!  I have been eager for this release due to a number of annoying bugs in 1.8.  Overall I thought 1.8 was a great step for Orchard but I have a couple sites waiting to upgrade due to these bugs.

Most notably for me, the following bugs have been fixed:

Caching errors – This would cause problems with form validation – messages would not be displayed on postback because Orchard was serving up a cached version.  The flag to tell Orchard not to show a cached version on postback is now working again.

Lists are now working properly – the issues with paging and disappearing lists in the Admin area should now be resolved.

Media gallery issues – images not displaying due to characters and some other small points have been fixed.

Overall 1.8.1 doesn’t bring a lot of new functionality but it cleans up some of the great features of 1.8.  It feels mostly like a bug patch, but that makes sense for a minor release.

You can see the full release report and bug fix list below.  Did any of these bugs cause issues for you?

Check it out here.

Manually Uninstalling a Broken Orchard Theme

I recently ran into a bit of a conundrum when working with an Orchard site.  I installed a theme that ended up being incompatible with my current version of Orchard, which broke the front end of my site.  To make matters worse, I somehow became logged out while experimenting with this.  If you’re like me and end up in this situation, you’ll find that there is no way to log back into your site to remove the broken theme, since you can’t access the login page.  Oops!

There is obviously a way to disable the theme through the database, which we’ll cover here.  It’s pretty simple, really.  If you don’t have access to the database, I’m not sure how you would actually fix this.  Leave a comment if you know!

Open up your database in SQL Server.  There are two tables in particular we want to look at – Settings_ShellFeatureRecord and Settings_ShellFeatureStateRecord.  Delete any rows that have the name of your theme in them. 

Orchard 1.8 released!

Hey people,

Orchard 1.7.3 and 1.8 were released today…awesome! Sounds like it comes with a number of great improvements.  You can see the official release here.

Orchard 1.7.3 mostly just handles bug fixes, where as 1.8 adds some great enhancements and features.  I’ll try to cover some of these more in depth in future blog posts.  The highlights are listed below:

  • Supposedly a huge performance improvement by switching to an infoset structure for the database – content items are now stored as one XML entry in the database rather than every content part being stored in a separate table
  • Upgraded to ASP.NET 4.5 and MVC 5.1 with Razor 3.1
  • The once deprecated List Module is back and looks pretty awesome now. It basically lets you pick and choose random content items to add to a list that can be displayed as a page or widget. It also allows for sorting and can be restricted to certain content types, etc.  Kind of like a lightweight projector module if you’re familiar with that, though it’s designed to mirror the basic blog functionality.  This functionality kind of reminds me of a SharePoint List, though this is purely my opinion and is not meant to imply an technical similarities.
  • Job Queue Module – Not exactly sure how thie works, I’ll have to dig into it.  Seems like an improved way for queuing up tasks like sending emails or other workflow type setups.
  • Lots of bug fixes from 1.7.2 (I think the custom forms bug has been fixed)
  • Improved Caching
  • Azure improvements such as full Azure Media Services integration – from my understanding this means you can replace the media library with an Azure repository and also stream video through Azure
  • Media library enhancements (folders can now be collapsed!

Download it today and check it out!

Creating Content Fields Programmatically in Orchard

One of the most compelling features of Orchard is its strong support for building and managing Content Types right out of the box through the Admin UI.  However, there will almost certainly be times when you want to create Content Types programmatically.  Maybe you are looking to package the Content Types into a reusable plugin, or maybe you just want more control and structure over what gets built on your site.  Whatever the reason, building Content Types programmatically is actually pretty easy.

The Content Type system in Orchard is an expansive topic, so we will be focusing on only one aspect of it in this post.  Specifically, we are going to look at how to add the built in Content Fields to Content Types programmatically. This topic isn’t all that complicated, but the syntax can be confusing and documentation is a bit sparse if you’re looking for info on every Field type.  I am going to show code examples for a few types of field you can add to a Content Type, and then I will show you how to figure out the syntax for all the other types on your own.

Another small note: You can also create Content Fields and Content Parts in Orchard that are backed by strongly typed classes and database entries you define using custom schemas.  These types of Content Fields and Content Parts are useful if you want to add in some kind of custom logic when items are saved or retrieved, among other benefits.  However, in a lot of cases you just want to save and display the information directly entered by the user.  In these situations you simply need to tell Orchard what types of fields you want (what we are doing in this post) and it will handle the rest for you.  If none of that makes sense to you yet, don’t worry about it – you will know when you encounter a situation that requires Content Fields backed by logic.

Anyway, onto the task at hand!

Installing Orchard On Azure with a Custom Domain name

One of the great characteristics of Orchard is the ease at which you can get a site up and running, especially for development purposes. However, this process can be a bit of a headache with hosting providers that are not optimized for the type of environment Orchard demands – an IIS web server with a site running in full trust mode. Yes, you can technically run Orchard in medium trust, but you lose some optimizations. If you’re going to host Orchard on a third party provider, you want to make sure you’re getting the best environment possible. I have found Microsoft’s Azure to be a great choice for Orchard, partially due to its ability to install applications for you through its web application gallery.

To get started you’ll obviously need an Azure account, or at least sign up for a free trial. After you’re registered, head over to your dashboard and click on “Websites”. If you are just starting out with Azure, no websites will be listed, so click the “+ New” button in the bottom left corner. Choose “From Gallery” on the menu that pops up to open the Apps for Azure dialog.