Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Section blocks. #893

Closed
BradEstey opened this issue Oct 29, 2014 · 3 comments
Closed

[Proposal] Section blocks. #893

BradEstey opened this issue Oct 29, 2014 · 3 comments
Labels
Milestone

Comments

@BradEstey
Copy link

A similar idea has been discussed elsewhere (#208), but eventually went off the rails and fizzled. I'm proposing section blocks similar to those in Laravel's Blade Template that could look something like this:

Master Layout Template

{{!--app/views/layout/master.hbs--}}
<html>
    <head>
        <title>{{section "title" "Untitled Document"}}</title>
    <body>
        <nav>
        {{section "sidebar"}}
            <a href="/">Home</a>
            <a href="/blog">Blog</a>
        {{/section}}
        </nav>
        <article>
            {{>content}}
        </article>
    </body>
</html>

Edit User Form Partial

{{!--app/views/users/edit.hbs--}}
{{overwrite "title" "Edit User"}}
{{append "sidebar"}}
    <a href="/users">Users</a>
{{/append}}

<form method="post">
    <input type="text" />
    <button type="submit">Edit User</button>
</form>

Output

<html>
    <head>
        <title>Edit User</title>
    <body>
        <nav>
            <a href="/">Home</a>
            <a href="/blog">Blog</a>
            <a href="/users">Users</a>
        </nav>
        <article>
            <form method="post">
                <input type="text" />
                <button type="submit">Edit User</button>
            </form>
        </article>
    </body>
</html>

Here is a quick rundown of the 4 possible functions. Things could get much more complicated when you start nesting sections inside of other sections. This would also allow partials to easily be used inside of various layout templates and adapt according to the layout. If section doesn't exist in any of the parent templates then append, prepend, and overwrite return nothing.

Section

{{!--block--}}
{{section "name"}}
    <p>Default Section</p>
{{/section}}

{{!--string--}}
{{section "name" "string"}}

Append

{{!--block--}}
{{append "name"}}
    <p>Appends parent section if it exists, otherwise does nothing.</p>
{{/append}}

{{!--string--}}
{{append "name" "string"}}

Prepend

{{!--block--}}
{{prepend "name"}}
    <p>Prepends parent section if it exists, otherwise does nothing.</p>
{{/prepend}}

{{!--string--}}
{{prepend "name" "string"}}

Overwrite

{{!--block--}}
{{overwrite "name"}}
    <p>Overwrites parent section if it exists, otherwise does nothing.</p>
{{/overwrite}}

{{!--string--}}
{{overwrite "name" "string"}}
@kpdecker
Copy link
Collaborator

kpdecker commented Nov 8, 2014

This requires some fairly large changes to how Handlebars renders templates due to the need to change sections of the output after it has rendered the initial time. It's not impossible but it will take a fair amount of work.

@kpdecker kpdecker added this to the Backlog milestone Nov 8, 2014
@kflorence
Copy link

@kpdecker
Copy link
Collaborator

kpdecker commented May 5, 2015

Closing in favor of #1018. That has not implemented yet so comments are requested.

@kpdecker kpdecker closed this as completed May 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants