title: Razor view engine for ExpressJS
body: <p>I've been toying around with NodeJS, ExpressJS etc, and would really like to be able to have a template engine closer to ASP.Net MVC's Razor engine for node (jshtml).  I'm curious if anyone is familiar with such a beast, or something closer to it.</p>
  
  <p>The main feature I am wanting is region/section based inserts against a master/parent layout/template, which doesn't seem to be a feature in the template engines for node I have seen so far.</p>
  
  <hr>
  
  <p><strong>-- edit: 2012-02-09 --</strong></p>
  
  <p>I'm essentially wanting to be able to do the following...</p>
  
  <p>_layout.jshtml</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;!-- meta tags, etc --&gt;
  
    &lt;!-- title set in page --&gt;
    &lt;title&gt;@ViewBag.Title&lt;/title&gt;
  
    &lt;!-- site-wide styles --&gt;
  
    @RenderSection("Styles", false)
  &lt;/head&gt;
  &lt;body class="@ViewBag.PageClass"&gt;
    &lt;!-- site-wide header --&gt;
  
    &lt;div id="side_content"&gt;
      @RenderSection("Side", false)
    &lt;/div&gt;
  
    &lt;div id="main_content"&gt;
      @RenderBody()
    &lt;/div&gt;
  
    &lt;!-- site-wide footer --&gt;
  
    &lt;!-- site-wide scripts --&gt;
  
    @RenderSection("Scripts", false)
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  
  <p>mypage.jshtml</p>
  
  <pre><code>@{
    ViewBag.Title = "My Page";
    ViewBag.PageClass = "page-x";
  }
  
  @section Styles {
    &lt;link ... /&gt;
  }
  
  @section Scripts {
    &lt;script type="text/javascript"&gt;
      var pagesettings = @Html.Raw(Model.SomeJsonContentFromController);
    &lt;/script&gt;
  }
  
  @section Side {
    side content here
  }
  
  main content here</code></pre>
  
  <hr>
  
  <p>Which is pass certain criteria from the view into the layout including multiple sections.  I haven't seen an example of how to do this in Jade or EJS, if it's possible I would appreciate the insight.</p>
  
  <hr>
  
  <p><em>-- edit: 2012-02-13 --</em></p>
  
  <p>It looks like ExpressJS 3 + Jade there are now "extends" and "block" keywords for defining precisely what I was looking for.  Example taken <a href="http://www.devthought.com/code/use-jade-blocks-not-layouts/" rel="nofollow noreferrer">from here</a>.  Thanks to <a href="https://stackoverflow.com/users/6845/don">@Don</a> for his answer &amp; comment.</p>
  
  <pre><code>// my-template.jade
  extends my-layout
  
  // only guessing this var will be passed to the layout (testing later)
  - var pageTitle = "My Template";
  - var pageClass = "my-template";
  
  block styles
    style(type="text/css")
  
  block scripts
    script(src="myscript.js")
  
  block side
    div Side Content Here
  
  block main
    div Main Content Here
  </code></pre>
  
  <pre><code>//my-layout.jade
  doctype 5
  html
    head
      title #{pageTitle} - My Site
    body(class=pageClass)
      #side
        block side
      #main
        block main
      block scripts
  </code></pre>
  
  <p>I'm not 100% sure about some aspects above (namely variables carrying to the layout from the template... will try to confirm later.</p>