Shawn Weisfeld

I find when I talk to myself nobody listens. - Shawn Weisfeld
posts - 356, comments - 173, trackbacks - 34

My Links

News

The views expressed in this blog are mine and mine alone, not that of my employer, Microsoft, or anyone else’s. No warrantee is given for the quality of any material on this site.

Archives

Post Categories

Create a template for Orchard

Orchard the open source CMS from Microsoft (http://www.orchardproject.net/) has a great tempting engine. The out of the box base template “The Theme Machine” is very powerful and flexible, however if you are as design challenged as I, creating something with it that looks decent is out of the question. To that end I use a very cool template builder, Artisteer (http://www.artisteer.com/) if that is not your speed there are about a million websites where you can download free/low cost templates, however most of them generate a standard HTML page with some javascript and css. I wanted to take a minute to document how I converted my HTML template into an Orchard theme.

(Disclaimer this worked for my site, your template might require some different html changes, especially when it comes time to edit the HTML and CSS)

Step 1: Get the html template. (Did I really need to tell you that?)

Step 2: The goal is to make a theme based on the base template “The Theme Machine”. You will need to follow the instructions on the Orchard site to “Generate a New Theme” http://www.orchardproject.net/docs/Writing-a-new-theme.ashx, however their instructions have you creating an empty theme. We need to create one based on “The Theme Machine”. To do that just alter the codegen step to use the following command:

>> codegen theme MyTheme /BasedOn:TheThemeMachine /CreateProject:true /IncludeInSolution:true

Step 3: Copy the CSS & related images into the “Styles” folder of your new theme

Step 4: Copy the javascript into the “Scripts” folder of your new theme

Step 5: Copy the template html file into the Views folder. I do this so that I have it for safe keeping and it stays with the project. Orchard will not be using it directly.

Step 6: Copy the “Layout.cshtml” file from the “Views” folder from the “TheThemeMachine” template into the “Views” folder of our new theme.

Step 7: This is the hard part, time to merge the HTML template that you found/created in Step 1 with the Layout.cshtml file you copied into your “Views” folder in Step 6.

There are 2 things that you will have to worry about here:

First you need to add references for the css and js files. My template requires 3 css files and 1 js file, so I needed to add the following at the top of the layout.cshtml file. I put mine just below the includes “Style.Include” statements that were already in the file.

My template looks like this:

clip_image002

Converted to the layout.cshtml file it looks like:

image

Now that we have the head tag filled with all its goodness, it is time to do the body part. Copy over the html from the template into your Layout.cshtml file. You want to copy the html just below the “@tag.StartElement” line of code. With the markup in place, start moving the placeholders from the Layout.cshtml file into the proper places in your new template.

Once you have moved the placeholders around, you will probably need to add a css file tweak everything just right.

Step 8: The menu. My template and my client required a drop down menu, however out of the box Orchard only supports a single level menu. Time to add a module, the “Advanced Menu” module from Piotr Szmyd to be specific. After installing this module you will now have the ability to create multi level menus. However it comes with its own look and feel. If this works for you great, if not, you will have to modify it. Since my template provides for a menu that I like I am going to use it. To do so I need to copy 2 more cshtml files into my "Views” folder. After adding the module you should see a folder for it listed in your “Modules” folder called “Szmyd.Orchard.Modules.Menu”. In there you will find a “Views” folder and in it you will see Menu.cshtml, and MenuItem.cshtml. Copy those two files into the "Views” folder of your theme. Now alter them to match your template, just like you did the layout.cshtml file.

Print | posted on Sunday, August 28, 2011 2:08 PM |

Feedback

Gravatar

# re: Create a template for Orchard

Hi Shawn,

I am very new to Orchard, so....

Thanks for writing this article. It's been a great help.

It would really help me and the rest of the community if you could extend this article to include a full in depth walk through of converting a HTML template to an Orchard theme.

Please take a look at the link below. It looks like nobody has done this before.

http://orchard.codeplex.com/discussions/353617

It would be good if you could share your experience in this area and help the newbe Orchard developers like me. What do you think?

Regards,

Paul.
5/2/2012 5:01 AM | Paul Wade

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 2 and 7 and type the answer here:

Powered by: