In an earlier article in this series on the new WebMatrix suite of technologies from Microsoft, I described how we are supporting the use of Razor scripts in DotNetNuke, by providing a “Razor Host” module. 

Having created this cool new Razor script, how do you go about distributing it? 

In this article I will describe how you can package the script up as a module.  Using the initial prototype of the “Razor Host” module, some of the steps are manual, but in a future iteration we expect to add a packaging feature to the module to automate the process.

Creating the Initial Script

Obviously the first step is to create the script.  In this example I am going to use one of the scripts that are included with the Razor Host module – Twitter.cshtml.

Figure 1 – The Twitter.cshtml Script

Razor_Module_01

 

Creating the Module

The next step in the process is to “create” a new Module based on this script.  This is done by taking advantage of one of the properties in the RazorModuleBase base class – RazorScriptFile.  In my previous post I showed that the default implementation of RazorScriptFile loads the script file with the same name as the ascx file.

We therefore create a simple ascx file under DesktopModules for our “Twitter” module (Figure 2)

Figure 2 – Creating the Twitter Module

Razor_Module_02

In this example I have created a “Razor Modules” folder, and under that a “Twitter” folder, where I have created the Twitter.ascx file and copied the Twitter.cshtml script from my Razor Host Module.  The ascx file is very simple – it has a single line of code at the top of the file (which will be the same for all Razor script modules).

<%@ Control AutoEventWireup="false" Inherits="DotNetNuke.Web.Razor.RazorModuleBase" %>

By inheriting from the RazorModuleBase base class – and naming our ascx file - Twitter.ascx, the RazorModuleBase base class automatically tries to load the file - Twitter.cshtml.

So, we have “created” our module.  The last step is to package it for distribution.  In order to package the module we need to register it in our dnn development site.  We can do this using the “Create New Module” action under Host/Module Definitions (Figure 3), in exactly the same way as Shaun Walker described in a recent blog on creating Modules.

Figure 3 – Registering the Twitter Module in Module Definitions

Razor_Module_03

Now we have registered the module we can package it using the built-in packager – just as we can with any DotNetNuke module.

The packager automatically detects both the ascx file and the cshtml file (Figure 4).

Figure 4 – Packaging the Twitter Module

Razor_Module_04

The zip package created by the Packager can then be distributed to anyone who has the Razor Host Module installed – the requirement for the presence of the Razor Host module is that this module installs a number of dependent assemblies that are necessary for Razor support to work.  When we add packaging to the Razor Host module itself this dependency will go away as we will automatically include all the assemblies and files necessary to make the module work.


 Search Blog

 Calendar

«  May 2012  »
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910
View posts in large calendar

 Tags

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2012 Thoughts from the Wet Coast