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

Question about partial context (v3.0.0 ~ v4.0.5) #1139

Closed
zordius opened this issue Nov 28, 2015 · 6 comments
Closed

Question about partial context (v3.0.0 ~ v4.0.5) #1139

zordius opened this issue Nov 28, 2015 · 6 comments

Comments

@zordius
Copy link

zordius commented Nov 28, 2015

Question 1: Can we use partial block inside a partial block?

Question 2: When the outer partial block pushed 1 context stack (need to use ../ to refer to original context) , why the inner partial block did not change the context stack? Please refer to this jsfiddle: http://jsfiddle.net/z3fwhmwL/

Template:

~{{#> dude}}={{../foo}}={{#> ya}}@{{../foo}},{{../../foo}}{{/ya}}={{/dude}}~

Data:

{foo: 'bar'}

Output:

~=bar=@bar,=~

My Expectation:

~=bar=@,bar=~

Question 3: When a partial provided for the outer partial block, the context is gone. Why? Please refer to this jsfiddle: http://jsfiddle.net/z3fwhmwL/1/

Provided partial:

Handlebars.registerPartial('dude', '!{{foo}}${{../foo}}%{{../../foo}}');

Output:

~!$%~

Question 4: When a partial provided for the inner partial block, the context is gone. Why? Please refer to this jsfiddle: http://jsfiddle.net/z3fwhmwL/2/

Provided partial:

Handlebars.registerPartial('ya', '!{{foo}}${{../foo}}%{{../../foo}}');

Output:

~=bar=!$%=~
@kpdecker
Copy link
Collaborator

  1. Yes
  2. Partials follow the same rules as helper calls, which changed in version 4 to avoid creating new depth values if the context has not changed. Discussion of this in Conditionals affect ../ path segment behaviour in blocks #1028.
  3. Global partials do not allow for depthed references, you'll need to pass in as a custom context.
  4. Same as above.

So basically this is all working as expected.

@zordius
Copy link
Author

zordius commented Nov 30, 2015

Thank you for your answers.

But for 2. , if partials should prevent context change, then the outer partial block should not change the context, right? (the inner partial block should follow the same rule with outer partial block, now their behaviors are different)

@kpdecker
Copy link
Collaborator

kpdecker commented Dec 3, 2015

Partials CAN change the context, but if they don't, then a new depth is not created. This matches the behavior you see with if under 4.

@zordius
Copy link
Author

zordius commented Dec 4, 2015

After some tests I found more issues.

Refer to this jsfiddle: http://jsfiddle.net/ymd1dg7o/

A. compare 1. with 3. , their behaviors are different.
B. check 4. and 5. , partials behavior changed? no any context be passed into partial.

Something strange in v3.0.0 ~ v4.0.5 (maybe it is a designed change?) ; here is another test with v2.0.0, http://jsfiddle.net/20sz0jbf/ . We can pass original context into partial by {{>foo}} or {{>foo .}} . But, now we only get empty context either by {{>foo}} or by {{>foo .}}

The issue title will be changed from Questions about partial block inside partial block (v4.0.5) to Question about partial context (v3.0.0 ~ v4.0.5)

@zordius zordius changed the title Questions about partial block inside partial block (v4.0.5) Question about partial context (v3.0.0 ~ v4.0.5) Dec 4, 2015
@kpdecker
Copy link
Collaborator

It looks like these issues spawn from the use of stringParams, which we did not account for when we were making the changes to depth handling. If you remove the stringParams option or run against the latest in master the results are all as expected
http://jsfiddle.net/qrdurwpn/

Closing this since stringParams will be desupported in 5, see #1145

@zordius
Copy link
Author

zordius commented Dec 14, 2015

Thank you for the clarify!

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

No branches or pull requests

2 participants