I am using popover to show user info on hovering username in my app. I have a meteor template with user info that needs to be shown. How can I include this template takes user object as parameter into popover content?
@jamgold how can i use Blaze.renderWithData() for content in popover? As a parentNode option I tried useing $(’.popover’)[0] but it is not working. so I have created my own parentNode as popover.
I alwasy thought about wrapping the following solution in a package, but it’s easy enough to implement it by hand.
I use [bootbox.js][1] but you can maybe adjust this for the popover thingy you use.
bootbox.dialog({
title: "Some Title",
message: " ", <-- it's important that the message isn't really empty.
buttons: {
cancel: {
label: "Cancel",
className: "btn-default",
},
ok: actionBtn, <-- since it has some logic, I define it in advance, but this has nothing to do with your question.
}
});
Blaze.renderWithData(Template.bootboxSomeTemplate, function() { return SomeCollection.findOne(dataAttributes._id) }, $('.bootbox-body')[0]);
This code basically creates and shows an empty bootbox dialog and injects the rendered template into the body of the dialog.
If you only show one dialog at a time, you can work with $('.bootbox-body')[0]) without a problem. Another way would be to put a <div> with an unique id in the message and then inject the template into this <div>.
If you don’t wrap the SomeCollection.findOne-part into a function, the data will not be reactive.
@HelloLudger thank you for your suggestion. bootbox shows a dialog box hiding the complete page like jquery lightbox. what wanted was something like bootstrap popover (like fb, on hover a username it shows user basic info).
I gaveup bootstrap popover and implemented my own with simple “div” to show or hide and position it where ever i need. it works like a charm. because im using Blaze.renderWithData() it is reactive too
You need to use the popover selector option for the parentNode and then listen for the shown.bs.popover event… and Blaze.renderWithData(...). I do the same thing for dynamic modals.
@jamesgibson thank you for your solution. but i have made a custom popover div with css arrow and used jquery and Blaze.renderWithData(). May be next time I will try your solution
Can you extend on this? I’m having problems too. If I left the fade class the template is not rendered. When I remove the fade class I got the popover rendered but then I cannot hide it using .popover('hide')