<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>just in ram &#187; Spark</title>
	<atom:link href="http://justinramel.com/tag/spark/feed/" rel="self" type="application/rss+xml" />
	<link>http://justinramel.com</link>
	<description>A list of stuff I should remember but never do</description>
	<lastBuildDate>Sat, 24 Jul 2010 10:14:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Setup ASP.NET MVC with Spark View Engine in 5 minutes or less</title>
		<link>http://justinramel.com/2009/06/08/setup-asp-net-mvc-with-spark-view-engine-in-5-minutes-or-less/</link>
		<comments>http://justinramel.com/2009/06/08/setup-asp-net-mvc-with-spark-view-engine-in-5-minutes-or-less/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 13:33:21 +0000</pubDate>
		<dc:creator>Justin Ramel</dc:creator>
				<category><![CDATA[Mvc]]></category>
		<category><![CDATA[Spark]]></category>
		<category><![CDATA[aspnetmvc]]></category>

		<guid isPermaLink="false">http://justinram.wordpress.com/2009/06/08/setup-asp-net-mvc-with-spark-view-engine-in-5-minutes-or-less/</guid>
		<description><![CDATA[Setup folder structure:
 
Download and put the asp.net mvc dll’s in mvc folder and spark dll’s in spark folder. 
Create a new asp.net application not a mvc application just a standard asp.net application. This means you will not get the mvc helpers for creating controllers and views but that’s not a massive loss and has [...]]]></description>
			<content:encoded><![CDATA[<p>Setup folder structure:</p>
<p><a href="http://justinram.files.wordpress.com/2009/06/image.png"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="image" border="0" alt="image" src="http://justinram.files.wordpress.com/2009/06/image_thumb.png" width="108" height="130" /></a> </p>
<p>Download and put the <a href="http://www.asp.net/mvc/download/" target="_blank">asp.net mvc</a> dll’s in mvc folder and <a href="http://sparkviewengine.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=27109" target="_blank">spark</a> dll’s in spark folder. </p>
<p>Create a new asp.net application not a <strong>mvc</strong> application just a standard asp.net application. This means you will not get the mvc helpers for creating controllers and views but that’s not a massive loss and has the advantage that you don’t need the asp.net mvc installed if you open the solution on another machine.</p>
<p><a href="http://justinram.files.wordpress.com/2009/06/image1.png"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="add new project" border="0" alt="add new project" src="http://justinram.files.wordpress.com/2009/06/image_thumb1.png" width="644" height="413" /></a>Change content of Default.aspx to: &lt;!&#8211; Placeholder do not delete! &#8211;&gt;</p>
<p>The default.aspx placeholder is required to allow the asp.net routing to work. </p>
<p>Delete the code behind files for Default.aspx (Default.aspx.cs, Default.aspx.designer.cs) they are not needed.</p>
<p>Add references to the Spark.dll and Spark.Web.Mvc.dll located in the libs folder.</p>
<p><a href="http://justinram.files.wordpress.com/2009/06/vs_add_ref.png"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="vs_add_ref" border="0" alt="vs_add_ref" src="http://justinram.files.wordpress.com/2009/06/vs_add_ref_thumb.png" width="608" height="484" /></a> </p>
</p>
<p>Add references to asp.net mvc System.Web.Routing.dll, System.Web.Abstractions.dll, System.Web.Mvc.dll</p>
<p><a href="http://justinram.files.wordpress.com/2009/06/image2.png"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="image" border="0" alt="image" src="http://justinram.files.wordpress.com/2009/06/image_thumb2.png" width="608" height="484" /></a> </p>
<p>Add spark to the web.config:</p>
<p>&#160; &lt;/sectionGroup&gt;    <br />&#160; &lt;section name=&quot;spark&quot; type=&quot;Spark.Configuration.SparkSectionHandler, Spark&quot;/&gt;     <br />&lt;/configSections&gt; </p>
<p>&lt;spark&gt;    <br />&#160; &lt;compilation debug=&quot;true&quot; /&gt;     <br />&lt;/spark&gt; </p>
<p>Debug true shows compilation errors when rendering views.</p>
<p>Add routing to httpModules section of web.config:</p>
<p>&lt;add name=&quot;UrlRoutingModule&quot; type=&quot;System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&quot;/&gt; </p>
<p>Add a application.cs which creates the routes and registers the spark view engine:</p>
<p>using System.Collections.Generic;    <br />using System.Web.Mvc;     <br />using System.Web.Routing;     <br />using Spark.Web.Mvc; </p>
<p>namespace Web    <br />{     <br />&#160;&#160;&#160; public class Application     <br />&#160;&#160;&#160; {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; public void RegisterRoutes(IList&lt;RouteBase&gt; routes)     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; routes.Add(new Route(     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &quot;{controller}/{action}/{id}&quot;,     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; new RouteValueDictionary(new {controller = &quot;home&quot;, action = &quot;index&quot;, id = &quot;&quot;}),     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; new MvcRouteHandler()));     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; } </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public void RegisterViewEngine(IList&lt;IViewEngine&gt; engines)    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SparkEngineStarter.RegisterViewEngine(engines);     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }     <br />&#160;&#160;&#160; }     <br />}</p>
<p>Add a global.asax with the following code behind.</p>
<p><a href="http://justinram.files.wordpress.com/2009/06/image3.png"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="image" border="0" alt="image" src="http://justinram.files.wordpress.com/2009/06/image_thumb3.png" width="644" height="389" /></a> </p>
<p>using System;    <br />using System.Web;     <br />using System.Web.Mvc;     <br />using System.Web.Routing; </p>
<p>namespace Web    <br />{     <br />&#160;&#160;&#160; public class Global : HttpApplication     <br />&#160;&#160;&#160; {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; protected void Application_Start(object sender, EventArgs e)     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var app = new Application();     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; app.RegisterRoutes(RouteTable.Routes);     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; app.RegisterViewEngine(ViewEngines.Engines);     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; } </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; protected void Application_BeginRequest(object sender, EventArgs e)    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; string path = Request.AppRelativeCurrentExecutionFilePath;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (string.Equals(path, &quot;~/default.aspx&quot;, StringComparison.InvariantCultureIgnoreCase) ||     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; string.Equals(path, &quot;~/&quot;))     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Context.RewritePath(&quot;~/Home&quot;);     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }     <br />&#160;&#160;&#160; }     <br />}</p>
<p>Create content, controllers and view folders in the root of the asp.net project:</p>
<p><a href="http://justinram.files.wordpress.com/2009/06/image4.png"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="image" border="0" alt="image" src="http://justinram.files.wordpress.com/2009/06/image_thumb4.png" width="323" height="484" /></a> </p>
<p>Create a shared folder in the views folder with a _global.spark file this will be used to share come code with all views.</p>
<p>&lt;use namespace=&quot;System.Collections.Generic&quot;/&gt;    <br />&lt;use namespace=&quot;System.Web.Mvc.Html&quot;/&gt;</p>
<p>Create a layouts folder in the views folder with a file called application.spark which will be used for the layout of the application very much like a master page.</p>
<p>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</a>&gt;     <br />&lt;html xmlns=&quot;<a href="http://www.w3.org/1999/xhtml&quot;">http://www.w3.org/1999/xhtml&quot;</a>&gt;     <br />&#160;<br />
&lt;head&gt;     <br />&#160;&#160;&#160; &lt;title&gt;Sample&lt;/title&gt;     <br />&#160;&#160;&#160; &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;     <br />&#160; &lt;/head&gt;     <br />&#160; &lt;body&gt;     <br />&#160;&#160;&#160; &lt;h1&gt;Header&lt;/h1&gt;     <br /><strong>&#160;&#160;&#160; &lt;use content=&quot;view&quot;/&gt;      <br /></strong>&#160;&#160;&#160; &lt;h1&gt;Footer&lt;/h1&gt;     <br />&#160; &lt;/body&gt;     <br />&lt;/html&gt;</p>
<p>The use content view tag highlighted above is replaced by the current view returned by asp.net mvc.</p>
<p>Add a HomeController.cs under the controllers folder with the following content:</p>
<p>using System.Web.Mvc; </p>
<p>namespace Web.controllers    <br />{     <br />&#160;&#160;&#160; public class HomeController : Controller     <br />&#160;&#160;&#160; {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; public ActionResult Index()     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return View();     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }     <br />&#160;&#160;&#160; }     <br />}</p>
<p>Under the views folder create a home\index.spark with the following content:</p>
<p>&lt;p&gt;Hello spark.&lt;/p&gt;</p>
<p>Run the project and you should get:</p>
<p><a href="http://justinram.files.wordpress.com/2009/06/image5.png"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="image" border="0" alt="image" src="http://justinram.files.wordpress.com/2009/06/image_thumb5.png" width="644" height="477" /></a> </p>
</p>
</p>
</p>
<p>You can download this sample solution <a href="http://fppuvw.bay.livefilestore.com/y1puB8Efa8gk4G6CzMEi40m1JxymO-5kxvTnYWbZ3uh1YZD71y8xOd58vSLWuNpPG06X9y7MgTOntrkvH82-jAqoMWnN9ranxJ6/sparksetup.zip?download" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://justinramel.com/2009/06/08/setup-asp-net-mvc-with-spark-view-engine-in-5-minutes-or-less/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
