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

Dynamic Partials #375

Closed
karlhorky opened this issue May 17, 2015 · 13 comments
Closed

Dynamic Partials #375

karlhorky opened this issue May 17, 2015 · 13 comments
Milestone

Comments

@karlhorky
Copy link
Contributor

As mentioned in #349, dynamic partials were added to Handlebars.js in handlebars-lang/handlebars.js#941. They are invoked using the following syntax.

{{> (partialNameHelper) }}

In order to use context variables, Handlebars.js uses the lookup helper like this:

{{> (lookup . 'myVariable') }}

However, the stringFormat helper looks like a viable alternative in Handlebars.java:

{{> (stringFormat "%s" myVariable) }}
@karlhorky karlhorky changed the title Dynamic Partials & Lookup Helper Dynamic Partials May 25, 2015
@karlhorky
Copy link
Contributor Author

Updated - the stringFormat helper can probably be used instead of a new lookup helper.

@jknack
Copy link
Owner

jknack commented May 25, 2015

Hi @karlhorky

I'm sorry but don't get how the lookup helper works and what impact it has inside the dynamic partial. Can you add an example?

Thanks

@karlhorky
Copy link
Contributor Author

Updated the original post again with an example of the lookup helper from Handlebars.js.

@karlhorky
Copy link
Contributor Author

But I think the stringFormat helper should work in Handlebars.java projects.

@jknack jknack added this to the 2.2.0 milestone May 26, 2015
@jknack jknack closed this as completed in 81df990 May 31, 2015
@karlhorky
Copy link
Contributor Author

Thanks @jknack!

@jknack
Copy link
Owner

jknack commented May 31, 2015

no problem and thank you for helping me to identify missing features of handlebars.java vs handlebars.js

I will push to maven central today, but I'm sure new release will be available tomorrow.

@karlhorky
Copy link
Contributor Author

Glad to help :)

@jknack
Copy link
Owner

jknack commented Jul 14, 2015

@karlhorky in the next few days, I'm going to release 3.0.0 is there any other pending js feature that we are missing? (compared to handlebarsjs 3.0.0)

thanks

@karlhorky
Copy link
Contributor Author

Actually, from our side, I haven't needed anything that's missing since Handlebars.java 2.2.0 was released.

Maybe anything else to be found here?
https://github.com/wycats/handlebars.js/blob/master/release-notes.md

Thanks for your hard work!

@karlhorky
Copy link
Contributor Author

Also check a bit earlier in the release notes - one of my issues was actually about a feature introduced in Handlebars.js 2.0.0 if I recall correctly.

@andreavaghi
Copy link

I don't get how i can use Dynamic Partials with Handlebars.java.

i've tried

{{> (dinamycPartial) }}

and

{{> (lookup '.' 'dinamycPartial') }}

where dynamicPartial is a String with the name of the template (es. "partials/test"), but it isn't working
i'm using 2.2.0

@jknack
Copy link
Owner

jknack commented Jul 20, 2015

here are some unit test that might help: https://github.com/jknack/handlebars.java/blob/master/handlebars/src/test/java/com/github/jknack/handlebars/i375/Issue375.java

also, make sure you don't have a typo: dinamycPartial vs dynamicPartial

@andreavaghi
Copy link

fortunately it was only a typo in the question!
looking at the test i've resolved with {{> (lookup . 'dynamicPartial' }}, removing the quotes around the dot

thank you for the really quick help

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

3 participants