Hello Orchard Part 2
Find out more about Orchard and how to create a simple Hello World module using latest change set from Codeplex from my first post here.
In my 1st port, I build a very simple module that displays “Hello World” on the front-end using the applied Orchard theme. We’ll also wire up the navigation menu to our module’s routes.
Hooking into the Admin Panel
The next thing we want to do is wire up our custom module to the admin panel, so we have a way to perform administration tasks on the back-end.
Objectives:
1. Add an admin panel page for the custom area
2. Add a menu item to the admin panel for the custom area
Follow These Steps:
1. Open up Orchard.Commerce project and right-click the “Controllers” folder and choose “Add > Controller…”
2. Type “AdminController” for the controller name and click [OK].
3. Add the following namespaces and attributes on the controller class:
using Orchard.Themes; using Orchard.UI.Admin; namespace Orchard.Commerce.Controllers{ [Admin] [Themed] public class AdminController : Controller
4. Right-click on the “Index()” method name and choose “Add View…”
5. Selected the “Create a partial view” option and click [Add]
6. Add the following HTML to the View page: <p>Commerce Area Admin</p>
7. Type Ctrl-F5 to build and run in VS.
8. Navigate to this URL in the browser: http://localhost:<port>/Admin/Commerce
ð Note that you will need to log in as admin before you can view this page. By convention, controllers named “Admin*” are protected from access by anonymous site visitors.
Hooking into the admin menu…
1. Add a reference to Orchard.Pages project
1. Add an AdminMenu.cs file to the root of the “OrchardCommerce” project. For convenience, you may copy this from another module folder (and change the namespace and area name appropriately).
using Orchard.Pages.Services; using Orchard.UI.Navigation; using Orchard.Localization; namespace Orchard.Web.Areas.Commerce{ public class AdminMenu : INavigationProvider { public Localizer T { get; set; } private readonly IPageService _pageService; public AdminMenu(IPageService pageService) { _pageService = pageService; } public string MenuName { get { return "admin"; } } public void GetNavigation(NavigationBuilder builder) { builder.Add(T("Commerce"), "20", menu => menu .Add(T("Manage Products"), "1.0", item => item .Action("Index", "Admin", new { area = "Orchard.Commerce" }))); } } }
2. Type Ctrl-F5 to build and run in VS.
3. Navigate to this URL in the browser: http://localhost:<port>/Admin
Orchard uses dependency injection to provide services to the application. In the example above, the INavigationProvider interface derives from IDependency. Simply by including a constructor that accepts INavigationProvider as a parameter, an implementation of this interface will be provided by the application framework to this class when it is constructed. We use this interface to define a main menu item for our Commerce > Manage Products screen. In the next section, we will see dependency injection again when we use the IRepository interface to access the database.
2 Responses to “Hello Orchard Part 2”
RSS feed for comments on this post. TrackBack URL

Hi There,
Great tutorial. Note that in latest version downloaded yestereday I think Orchard.Pages has been removed.
keep up the good work
thanks,
nick
Comment by nick — August 10, 2010 @ 12:04 pm
Yes I found the same, I ignored the Orchard.Pages reference and removed the IPageService code and it works. Great stuff, onto step 3 now
Comment by Gareth Mark Elms — August 29, 2010 @ 5:15 am