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

Partials with parameters #350

Closed
karlhorky opened this issue Feb 26, 2015 · 8 comments
Closed

Partials with parameters #350

karlhorky opened this issue Feb 26, 2015 · 8 comments
Milestone

Comments

@karlhorky
Copy link
Contributor

Can you support the handlebars.js partial parameters notation? Like in the spec here?

context

{
  "title": "profile",
  "dudes": [
    {
      "name": "Yehuda",
      "url": "http://yehuda"
    },
    {
      "name": "Alan",
      "url": "http://alan"
    }
  ]
}

index.hbs

<ul>
  {{#each dudes}}
    {{> dude title=../title class="list-item"}}
  {{/each}}
</ul>

dude.hbs

<li class="{{class}}">
  {{title}}: <a href="{{url}}">{{name}}</a>
</li>

expected output

<ul>
  <li class="list-item">
    profile: <a href="http://yehuda">Yehuda</a>
  </li>
  <li class="list-item">
    profile: <a href="http://alan">Alan</a>
  </li>
</ul>

I saw the #partial and #block helpers here, but I'm working on a project where we would like to keep parity with handlebars.js if possible.

@husayt
Copy link

husayt commented Mar 13, 2015

Seems this card needs to be merged with #349

@karlhorky
Copy link
Contributor Author

@husayt These partials were actually implemented in v2.0.0. So this is a bit older than v3.0.0 as in the other issue.

@superelement
Copy link

Has this been implemented? This feature is pretty useful.
Problem is, if you have an #each loop with a child partial in it, the child can't access properties of the parent scope. But if this feature is implemented, then the parent can specify those parameters on each child partial declaration.

@superelement
Copy link

@karlhorky
Copy link
Contributor Author

Thanks @jknack!

@felegy-norbert
Copy link

HI,
I am using the version 2.2.2 together with handlebars-v2.0, and I cannot get this parameter and partial thing working.

I have a very simple use case where:

{{> mypartial label="Value of the label" }}

mypartial.hbs.html
{{label}}

And it is not working. Do you see any problem with it? Also, can someone show me a working example?
Thank you.

@jknack
Copy link
Owner

jknack commented Jul 10, 2015

did you see any error? there are a few unit tests that demonstrate partials param in action. Here is one: https://github.com/jknack/handlebars.java/blob/master/handlebars/src/test/java/com/github/jknack/handlebars/i350/Issue350.java

@keesvandieren
Copy link

Partial parameters require the MapValueResolver.INSTANCE to be registered as resolver in the context. If partial parameters are not passed, this might be the reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants