SERIES: Writing an Orchard Twitter Widget - Creating a new custom module (3)

SERIES: Writing an Orchard Twitter Widget - Creating a new custom module (3)


This is part three of the series about how we can create a twitter widget for Orchard. We will guide you through the creation of a custom Orchard module that will serve Tweets from the Twitter Timeline of a specific user.

  1. Introduction
  2. Setup and configure an Orchard environment
  3. Creating a new custom module

Create or generate a new module

Orchard modules are ASP.NET MVC projects, similar to the concept of areas as in a regular ASP.NET MVC project.

There are a couple of ways you can create a new, custom module. The first solution would be to create a module manually. This way you can build the module completely on your own, making you responsible to add all the needed bits.

Another way would be to use the Orchard Command Shell. This tool provides you with several commands that help you to create Modules, Themes, enable Features etc. We are going to use the Command Line tool since this saves us some time and also because it is extremely easy to use.

Launch the Orchard Command Shell

To open the Orchard Command Shell you can either navigate to the directory or open the directory from Visual Studio, by right-clicking on the Orchard.Web project and select the Command-Line option. The Command-Line option is available in e.g. Visual Studio 2012 by installing the Productivity Power Tools 2012.

Writing an Orchard Twitter Widget

If not using any of these tools, you just simply navigate to the Orchard.Web folder and then go to the \bin folder, for example:


Inside this folder you will find a little program called Orchard.exe. This is the actual Orchard Command Shell. Let’s run this program.

Writing an Orchard Twitter Widget

So, one of the things that Orchard Modules can do is expose commands that are available to run in this command line environment. To get a list of commands that are already available from the core modules of Orchard, you can type:

orchard> help commands

What we want to do is create a new module and that command is available from the Orchard CodeGeneration module. This feature is not enabled by default, so we can either enable this through the backend, via the Modules section, or enable this using the Orchard Command Shell program. Let's try to enable this module by using the shell:

We can simply enable the feature by typing:

orchard> feature enable Orchard.CodeGeneration

Now the feature will be enabled and if we then again list all the available commands, we will see some new ones appear. The commands that come from the Orchard.CodeGeneration module start with codegen. So to create a new module, we can type:

orchard> codegen module “Konstrui.Twitter” /IncludeInSolution:true

We will use the IncludeInSolution flag to automatically add the new project under our Modules folder inside our Solution.

The CodeGeneration module created a whole new project for us and placed it into our solution. The project will look something like this:

New orchard project konstrui twitter

The project automatically configured the needed references to other projects in our solution, such as the Orchard.Core, Orchard.Framework and the also to the assemblies that are needed to run MVC, like System.Web.Mvc and System.Web.Routing.

Of course we do have the Models, Views and Controllers folders as well as a simple text file called Module.txt, which is our Module Manifest File, which contains the information about our project.

We will update the manifest file a bit, so that it describes our project more specifically.

Name: Konstrui Twitter
AntiForgery: enabled
Author: Daniel Plomp, Konstrui
Version: 1.0
OrchardVersion: 1.7
Description: Twitter widget for Orchard
        Name: Konstrui Twitter Widget
        Description: Twitter widget for Orchard that returns the user timeline (OAuth)
        Category: Social

This is really all you have to do to create an Orchard Module. Of course the next step is to implement the logic and functionality to let it do something useful.

Enable the module

To enable the module, we can go back to the Orchard Dashboard (backend) and navigate to the Modules section. If your site isn't running, just press CTRL-F5 to run it from Visual Studio, without debugging.

Under the category ‘Social’ we will find our new module which is disabled by default. We can just click Enable to activate it.

The next step will be to think about our models for the Twitter Widget (e.g. the tweets that will show up) and some global settings we need the user to enter (e.g. the tokens). 

Stay tuned!

door Daniel Plomp


RadEditor - HTML WYSIWYG Editor. MS Word-like content editing experience thanks to a rich set of formatting tools, dropdowns, dialogs, system modules and built-in spell-check.
RadEditor's components - toolbar, content area, modes and modules
Toolbar's wrapper 
Content area wrapper
RadEditor's bottom area: Design, Html and Preview modes, Statistics module and resize handle.
It contains RadEditor's Modes/views (HTML, Design and Preview), Statistics and Resizer
Editor Mode buttonsStatistics moduleEditor resizer
RadEditor's Modules - special tools used to provide extra information such as Tag Inspector, Real Time HTML Viewer, Tag Properties and other.