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

How to pass data between different templates in the same layout #30

Open
sf-wind opened this issue Jul 10, 2015 · 5 comments
Open

How to pass data between different templates in the same layout #30

sf-wind opened this issue Jul 10, 2015 · 5 comments

Comments

@sf-wind
Copy link

sf-wind commented Jul 10, 2015

I have a page with two sections, header and main, each has its own template. Some fairly expensive reactive data is needed by both templates. If the visitor browse another page, the reactive data should be destroyed. Is it possible to attach that reactive data to the route/layout?

Without FlowLayout's support, it is possible to create a parent template that includes both header and main templates, and pass the data to them. That parent template is actually the layout template. It means we need to create a separate layout template when some data is different. Does that make sense?

Say, I have the following layout:
FlowLayout.render ('layout', {header : 'headerTemplate', main : 'mainTemplate'});

I need to pass some complicated object data between headerTemplate and mainTemplate. Does it mean I need to create a new "layout" template?

@arunoda
Copy link
Contributor

arunoda commented Jul 10, 2015

Don't pass data via FlowLayout. Get data from the template itself. For an example, if your data inside the collection, simply access the collection in both of your templates.

@sf-wind
Copy link
Author

sf-wind commented Jul 10, 2015

The data is from an HTTP call to an external server. Because client side HTTP call has to be asynchronous, the data needs to be saved to a reactive variable and then the template re-renders itself.

I'd like to only make one HTTP call and render both templates.

Any way to achieve this?

@mcissel
Copy link

mcissel commented Aug 2, 2015

Save the HTTP request results in a Session variable. Use Session.get('results') in a helper in each template.

@sf-wind
Copy link
Author

sf-wind commented Aug 16, 2015

Yes, this is one method. I just want to avoid using global session variable as much as possible. It would be good that the router can provide such a functionality.

@frozeman
Copy link

frozeman commented Nov 5, 2015

+1

This for example can be necessary to set a templates state from the route. So passing data should definitely be possible, even if it is not reactive.

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

4 participants