-
Notifications
You must be signed in to change notification settings - Fork 312
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
this.options not available in view after rendering from server #363
Comments
Thanks for reporting - one way I've been getting around this is to have // views/base.js
var RendrView = require('rendr/shared/base/view');
module.exports = RendrView.extend({
// NOTE: you can run into problems if an attribute on a model is the same as the option passed in
getTemplateData: function () {
var data = RendrView.prototype.apply(this, arguments)
return _.extend(data, this.options)
}
}) I'll look into seeing if there is anyway we can get around having to do that. |
Thanks for reporting. I also had the same issue and tried to solve like @saponifi3d did. I also addressed a similar issue here: #399. Rendr is really good but these bugs are so annoying. |
If you are getting data from a fetch call - there needs to be a model / collection as it's set in the store - otherwise it needs to be created at the view level and passed in via the template itself or getTemplateData |
so i think this PR fixes this issue: #403 I'm still trying to figure out how i might be able to lock down that PR given a specific version of Rendr. However, if you are using master of rendr + that rendr-handlebars code it will only call initialize once and all of the options are passed through to that view. (it also fixes problems with |
Summary
When navigating to a route on the client side, I have
this.options
available within the view on the client side. However, when the route is loaded directly and rendered on the server I have access to the object on the server side but lose it client side.Example:
controllers/test_controller
views/test
Loaded indirectly
If I load
/
and navigate to/test
on the front-end, this console.log will output to my browser's console:Then when I click the button, this console.log will output to my browser's console:
Loaded directly
If I navigate to
/test
directly in my browser, this console will output to my NodeJS console:However, clicking the button will now output the following error to my browser's console:
Question
Is there another way to reliably have access to the object passed into the handlebars template from the controller?
The text was updated successfully, but these errors were encountered: