posts - 81, comments - 257, trackbacks - 0

Sunday, November 11, 2012

Migrating an MVC site to Orchard Project (Part 1)

I have been moving an asp.net MVC web site of mine to the Orchard Project. As a developer I love working with MVC, however, I had not found a nice solution for content management. All of the solutions were too intrusive, tainting the MVC flavor of the site, or rather young projects I didn't want to invest in. A recent survey of Content Management System (CMS) solutions found me looking right at the Orchard Project.

The project is not 'light', but it is very elegant. The project uses the 'MS Web Stack of love' which plays very nicely with my current MVC solution. Most important, at least to me, is that it has a bunch of really smart and dedicated people behind it, allowing me to learn and adopt some really great ideas while migrating.

Actually migrating the site has been a huge learning experience for me – I'm finding much of my knowledge of open source projects to be circa 2008/2009. There are a lot of ideas to absorb in the project, but they are good ideas. Some key points that would have helped me along with the integration.

  • I started with the source distribution of Orchard, unzipped it into a new location configured as a new website in IIS. From there I worked with the Visual Studio solution in the site root. I followed this guide: http://docs.orchardproject.net/Documentation/Manually-installing-Orchard-zip-file, but note the download link in the guide is old – use: http://orchard.codeplex.com/releases/view/90325 (or the newer download if 1.6 is old)
  • Orchard is extensible through modules, each of which is like its own MVC project. In my case it made sense to bring my existing MVC site into an orchard module. http://stackoverflow.com/questions/5269170/integrate-existing-asp-net-mvc-application-with-orchard-cms
  • Orchard uses the Razor view engine (you don't have – but I found it easier to, even though I am new to Razor). For me a big step in the migration was moving to Razor and cleaning up the Html.
  • Orchard uses Themes to control the look of the site. Thus, I migrated my masterpage(s)/design into a new Theme. http://docs.orchardproject.net/Documentation/Anatomy-of-a-theme, http://www.deepcode.co.uk/2011/05/real-world-orchard-cms-part-2-creating.html
  • Orchard allows for 'overloading' shapes/widgets (a 'view') through the Theme. If you want to redefine how the footer widget is rendered, for example, you would place a new Widget-Footer.cshtml in your Theme root. This definition would then override the default Orchard implementation. Similarly, to control the rendering of the Html Document, create your own Document.cshtml in the Theme. I found I was doing this a fair amount to control the output of my Theme.
  • Orchard also allows for 'Alternate' variations of shapes depending on the URL, for example. I used this to define an alternate Layout-homepage.cshtml to give my home page a different definition. Note you do have to install the Designer Helper Tools module for this too work (That stumped me for a bit) http://docs.orchardproject.net/Documentation/Alternates
  • When creating new 'Widgets' to serve as content regions, I found the wrapping with a div element and rendering the widget title in a header tag undesirable. I only wanted the Html Content of the widget rendered, not the extra wrapping tags. To remove the wrapping I added to the top of my widget "@{ Model.Metadata.Wrappers.Clear(); }", which prevented any Html being rendered around the widget. There's probably a better way to do this that I haven't found, though.

Currently I am migrating my MVC site into a module now that the Theme migration is complete.

posted @ Sunday, November 11, 2012 4:51 PM | Feedback (2) | Filed Under [ Web Programming ]

Powered by:
Powered By Subtext Powered By ASP.NET