kirbysayshi/vash

Sugar syntax for layout and partials

Opened this issue · 5 comments

Hi, as the title says it'd be great to have some sugar syntax to render a layout of a partial view in vash. For example, I'd call a view with res.render and then specify a layout like this:

@{
    Layout = "views/shared/_layout.vash";
}

And the way to import a partial view would be:

@RenderPartial("content")

And from the layout we can do this:

@RenderBody()

Including some sections

@RenderSection("foo")

And the way to specify sections:

@section foo{
   <p>Hello from foo</p>
}

This is how ASP.NET MVC razor syntax does, it'd be great if this is implemented and one suggestion to render content to it.

Alou?

@kirbysayshi are you there?

You should read the vash document first,Layout Helpers has a detailed description

Sure @bishanshan, it explains how to use the layout helpers using a sintax regard with jade templates. However, the main idea here is to use layout helpers with Asp.Net style that is explained above. You can notice the way to import templates is different as the docs says.

I'm interested in this too. Or rather, more generally interested why the tagline for vash says

Razor syntax, for JavaScript templates

But when one gets going with it, one quickly discovers the more jade-like patterns and noted lack of more Razor style directives ?

As an example, I was attempting to approximate a Razor template from an asp*net mvc project that uses @Html.Partial() (among other constructs I didn't find in vash), and wound up with this in my setup:

vash.config.helpersName = 'Html'

/**
 * Facade for Razor's .Partial()
 */
vash.helpers.Partial = function(viewName, viewBag) {
  return this.include( viewName, viewBag )
}

// now I can use @Html.Partial('my/view', myData)

... this is in a tiny expressjs setup, where I am only using express to bootstrap and compile/render my vash templates.

Disclosure: I've used plenty of other templating engines, but both vash and Razor are relatively new to me, so forgive me if this has been covered before/elsewhere.