In a stache template one can use the <content></content>
tags to render the contents contained within the component’s tags.
Is it possible to pass the contents to a helper as an argument or perhaps pass the contents to the viewModel?
In a stache template one can use the <content></content>
tags to render the contents contained within the component’s tags.
Is it possible to pass the contents to a helper as an argument or perhaps pass the contents to the viewModel?
Yes, via a section helper.
{{#if displayModal}}
{{#detach}}
<section class="modal-frame">
<div class="backdrop" ($click)="attr('displayModal', false)"></div>
<div class="popover-frame">
<content></content>
</div>
</section>
{{/detach}}
{{/if}}
can.Component.extend({
tag: 'popover-modal',
template: template,
leakScope: false,
viewModel: {
define: {
displayModal: {
value: false,
type: 'boolean'
},
embed: {
type: can.$
}
}
},
events: {
'{scope} embed': function( scope, ev, newEl, oldEl ) {
if (newEl) {
can.$(document.body).append(newEl);
}
if (oldEl) {
oldEl.remove();
}
},
destroy: function() {
var embed = this.scope.attr('embed');
if (embed) {
embed.remove();
}
can.Control.prototype.destroy.call(this);
}
},
helpers: {
detach: function( options ) {
this.attr('embed', options.fn().childNodes);
return options.inverse();
}
}
});