Does anyone know how to pass a dynamic parameter into a Spacebars helper?
The value of the parameter could be from the data context of the template/route that you’re in - or a javascript function that returns a string value, and the spacebars helper could be from a 3rd-party package that you don’t want to fork/alter.
So, this.document_id is the “dynamic” parameter brought in from the context, or it could be getDocumentId() from a JavaScript function, for example. But, we’re dealing with parsing it in the call for a Spacebars helper, so currently, that is being treated as a string literal. If you put it in braces like a helper, it doesn’t get parsed since we’re already inside of a helper call. Triple braces is just to make sure the content isn’t escaped, so that doesn’t work in this context either.
I’m sure this has been resolved prior, but I can’t seem to find any documentation or examples on how you would pass in a dynamic value to a Spacebars helper.
I have no trouble passing in dynamic data without braces and quotes, on the other hand I haven’t had to use helpers inside them before, so does this work?
No, unfortunately, when I use the above, docid is never rendered in the final textarea output. I used this.active_document but that’s a String property (via SimpleSchema) that stores the project’s active document’s ID (confirmed via Robomongo and set through fixtures).
The app doesn’t crash, but it’s as if the data is never parsed out correctly.
You’re right. I went back from the beginning and traced the “context” of the item throughout the route. It was lost prior to getting to that line of code.
I corrected it with a {{#with}} to correct the context, and it works as you stated.