Spark View Engine Intro

2,891 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,891
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Spark View Engine Intro

  1. 1. Introduction<br />Scott Cowansleepoverrated.com@Scottcowan<br />
  2. 2. What is it<br />View Engine for generating HTML (ie: ASPX)<br />Supported by Web Frameworks<br />ASP.Net MVC<br />Monorail<br />OpenRasta<br />
  3. 3. Advantages<br />Intellisense<br />Breakpoints in the view<br />Can generate a HTML from the view with Xpark.exe<br />Very readable (&lt;% %&gt; tags scare people)<br />
  4. 4. Advantages<br />Lets you use other languages in the view<br />C#<br />Visual Basic<br />IronPython<br />IronRuby<br />
  5. 5. Disadvantages<br />Error pages are ugly and hard to read<br />Intellisense hard to setup<br />Try unistallingresharper first<br />I feel like I’m doing ColdFusion again<br />
  6. 6. Hello World<br />&lt;p&gt;Hello ${&quot;World&quot;}!&lt;/p&gt;<br />Or you can use this if you must<br />&lt;p&gt;Hello &lt;%= &quot;World!&quot;%&gt;&lt;/p&gt;<br />
  7. 7. If blocks<br />&lt;test if=&quot;name == &apos;acme&apos;&quot;&gt;<br /> acme is my favourite.<br /> &lt;else/&gt;<br /> ${name} is okay too I suppose. <br />&lt;/test&gt;<br />
  8. 8. If Attribute<br />&lt;div if=&quot;name == &apos;alpha&apos;&quot;&gt;a&lt;/div&gt;<br /> &lt;div elseif=&quot;name == &apos;beta&apos;&quot;&gt;b&lt;/div&gt;<br /> &lt;else&gt;<br /> &lt;div&gt;g&lt;/div&gt;<br /> &lt;/else&gt;<br />
  9. 9. For loops<br />&lt;varnames=&quot;new[] { &apos;alpha&apos;, &apos;beta’}&quot;/&gt;<br />&lt;for each=&quot;var name in names&quot;&gt;<br />${name}<br />&lt;/for&gt;<br />
  10. 10. Each Attribute<br />&lt;varnames=&quot;new[] { &apos;alpha&apos;, &apos;beta&apos; }&quot;/&gt;<br />&lt;div each=&quot;var name in names&quot;&gt;<br />${name}<br />&lt;/div&gt;<br />
  11. 11. ViewData<br />View<br />&lt;viewdatacurrentProduct=&quot;Product&quot;/&gt;<br />${currentProduct.Name}<br />Controller<br />ViewData.Add(&quot;currentProduct&quot;, new Product {Name = &quot;Acme Car&quot;});<br />
  12. 12. Partial Views<br />Partial.spark<br />&lt;viewdataproduct=&quot;Product&quot; /&gt;<br />&lt;sample data=&quot;product&quot;/&gt;<br />Shared/_sample.spark<br />&lt;default data=&quot;Product&quot;/&gt;<br />${data.Name}<br />
  13. 13. Master Pages<br />Layouts/Application.spark<br />&lt;usecontent=&quot;head&quot;/&gt;<br />Index.spark<br />&lt;content name=&quot;head&quot;&gt; <br /> &lt;script /&gt;<br />&lt;/content&gt;<br />
  14. 14. Inline code<br />&lt;varnum=&quot;2&quot; /&gt;<br /># var total = num * 12;<br />${num} * 12 = ${total}<br />
  15. 15. ASP.Net MVC Setup<br />protected void Application_Start()<br /> {<br />RegisterRoutes(RouteTable.Routes);<br />SparkEngineStarter.<br />RegisterViewEngine(ViewEngines.Engines);<br /> }<br />
  16. 16. Introduction<br />Scott Cowansleepoverrated.com@Scottcowan<br />

×