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] Access context of another template #1316

Closed
MFlyer opened this issue Feb 27, 2017 · 2 comments
Closed

[Question] Access context of another template #1316

MFlyer opened this issue Feb 27, 2017 · 2 comments

Comments

@MFlyer
Copy link

MFlyer commented Feb 27, 2017

Hi all,
after googling about this didn't find a solution/docu so, asking here:

I have one page loading 2 different templates, each template with its own context, let's call them

A = template ( {'some_varA' : 'some_valA'} );
B = template ( {'some_varB' : 'some_valB'} );

From B template I can get {{some_varB}}, but I'd like to know if i can get some_varA too without using ad hoc Helpers or Partials?

Thanks
Mirko

@nknapp
Copy link
Collaborator

nknapp commented Mar 4, 2017

If you want to access some_varA, you have to pass it to the template-function (i.e. mix it into the other object like

B = template ({
    'some_varB' : 'some_valB',
    'some_varA' : 'some_valA' 
} );

Is this not possible in your case?

@MFlyer
Copy link
Author

MFlyer commented Mar 4, 2017

Hi @nknapp ,
I know I can do this passing it to B template, but it was a dict with dynamic fields (some fields can be undefined too) so I was looking for the most elegant way to do this.
At the end I had it with hacking Handlebars.registerPartial, used to define some globas instead of subtemplating :)
Mirko

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