Reputation: 546
So I'm building a view for a disqus comment widget. Since (generally) you would put disqus on a static page (not dynamic like a page rendered with Ember) I have to pass some extra parameters to the Disqus API to refresh the page. In order to do so, I need to pass an identifier to the API. So right now, I have a routing structure like /posts/:id . So I want to pass that ID to the Disqus view, but I'm not sure how -- or if I'm understanding the Ember architecture properly. If somebody could point me in the right direction, that would be awesome.
Here's how I'm calling the DisqusView in my post template (this using jade as my server templating lang).
div(class="post limit-width")
h3 {{headline}}
p {{body}}
h6
em Posted by {{creator}} on {{created}}
{{ view App.DisqusView identifier=id }}
My DisqusView looks like this.
App.DisqusView = Em.View.extend({
tagName: 'div',
//controller: App.MapController,
didInsertElement: function(){
this.get('element').id = 'disqus_thread';
console.log(this.get('identifier'));
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'sitename'; // required: replace example with your forum shortname
var identifier = new Date().getTime();
this.set('identifier', identifier);
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
}
});
So this works; it actually renders the Disqus control, but when I log the identifier on the console, all I see is "id" and not the actual id that's available in the post template. So I just need a way to access that "identifier" value.
Upvotes: 0
Views: 115
Reputation: 10552
(1) You can use id="disqus_thread" in the {{view}} helper to set the ID. Don't modify the element of the view directly.
(2) Use identifierBinding="id" so the view helper knows to follow the path specified, otherwise it'll be treated as a value.
Upvotes: 2