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.
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.
-- edit: 2012-02-09 --
I'm essentially wanting to be able to do the following...
_layout.jshtml
<!DOCTYPE html> <html> <head> <!-- meta tags, etc --> <!-- title set in page --> <title>@ViewBag.Title</title> <!-- site-wide styles --> @RenderSection("Styles", false) </head> <body class="@ViewBag.PageClass"> <!-- site-wide header --> <div id="side_content"> @RenderSection("Side", false) </div> <div id="main_content"> @RenderBody() </div> <!-- site-wide footer --> <!-- site-wide scripts --> @RenderSection("Scripts", false) </body> </html>
mypage.jshtml
@{ ViewBag.Title = "My Page"; ViewBag.PageClass = "page-x"; } @section Styles { <link ... /> } @section Scripts { <script type="text/javascript"> var pagesettings = @Html.Raw(Model.SomeJsonContentFromController); </script> } @section Side { side content here } main content here
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.
-- edit: 2012-02-13 --
It looks like ExpressJS 3 + Jade there are now "extends" and "block" keywords for defining precisely what I was looking for. Example taken from here. Thanks to @Don for his answer & comment.
// 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
//my-layout.jade doctype 5 html head title #{pageTitle} - My Site body(class=pageClass) #side block side #main block main block scripts
I'm not 100% sure about some aspects above (namely variables carrying to the layout from the template... will try to confirm later.
Express is currently, and for many years, the de-facto library in the Node. js ecosystem. When you are looking for any tutorial to learn Node, Express is presented and taught to people. In the latest State of JS survey, Express was TOP 1 for all categories.
js, or simply Express, is a back end web application framework for Node. js, released as free and open-source software under the MIT License. It is designed for building web applications and APIs.
What is Express JS – Quick Overview. ExpressJS is a web application framework for NodeJS. That's what mainly makes the difference between Express JS and Node JS. The former provides various features that make web application development fast and easy, which otherwise takes more time using only the latter.
Razor View Engine is a markup syntax which helps us to write HTML and server-side code in web pages using C# or VB.Net. It is server-side markup language however it is not at all a programming language.
Vash is the most feature complete and up-to-date razor clone I have found yet. Definitely check that one out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With