shannonmoeller / handlebars-layouts

Handlebars helpers which implement layout blocks similar to Jinja, Nunjucks (Swig), Pug (Jade), and Twig.
http://npm.im/handlebars-layouts
MIT License
361 stars 29 forks source link

Shorthand syntax for simple use cases #11

Closed kflorence closed 9 years ago

kflorence commented 10 years ago

It would be nice if there were defaults for simple use cases, for example when a layout has only one block.

Take the following example:

Layout:

<div class="component">
  {{#block "content"}}
    component content goes here
  {{/block}}
</div>

Page:

{{#layout "component"}}
  {{#content "content"}}
    component content goes here
  {{/content}}
{{/layout}}

I could instead write something shorter, like:

{{#layout "component" content="component"}}
  component content goes here
{{/layout}}

Or:

{{#layout "component"}}
  {{content}}
    component content goes here
  {{content}}
{{/layout}}

Where {{content}} without a name defaults to some value, like "content". This same syntax should also be available for embeds.

shannonmoeller commented 10 years ago

I could see a case for this, but I have some reservations. Primarily, it changes the assumptions about how the plugin works, namely it makes {{#extend}} and {{#embed}} act like a {{#content}} block, even though they currently serve very different purposes.

If I were to implement this, I think I'd simplify the use to something like this:

<!-- layout.hbs -->
<div>{{#block}}{{/block}}</div>

<!-- page.hbs -->
{{#extend "layout"}}
    content goes here
{{/extend}}

But that brings up another case where someone might expect this to also work:

<!-- page.hbs -->
{{#extend "someOtherLayout"}}
    content goes here

    {{#content "header"}}
        and more goes here
    {{/content}}

    {{#content "footer"}}
        and a little goes here too
    {{/content}}
{{/extend}}

Right now, I think this complicates things more than it helps. I'll leave this issue open for a while longer to see if anyone else chimes in, but as it stands, I'm not inclined to implement this.

shannonmoeller commented 9 years ago

Closing for now. Again, if there's more demand for it, I'm willing to revisit.