XaminProject / handlebars.php

Handlebars processor for php
331 stars 132 forks source link

Support for context passed into a partial as an argument #15

Closed daviddeutsch closed 11 years ago

daviddeutsch commented 11 years ago

I tried to look this up in the handlebars and mustache documentation, but it seems undocumented. Anyways, partials should be able to accept an argument that establishes a new context:

http://stackoverflow.com/questions/11523331/passing-variables-through-handlebars-partial

Example

base.hbs:

{{> files files}}

files.hbs:

{{#each this}}
    <file>{{this}}</file>
{{/each}}

data:

{
    "files":[
        "file1.txt",
        "file2.txt"
    ]
}

Before my pull request, you would get an error that the template "files files" wasn't found. With the pull request, the template renders the property "files" as "this". The result looks like this:

<file>file1.txt</file>
<file>file2.txt</file>
everplays commented 11 years ago

thanks @daviddeutsch.

daviddeutsch commented 11 years ago

Pleasure as always.