I have trouble using ‘partials’ within Template7 helpers. Not sure if it is me or a ‘bug’ or something that just is not supported.
If I wrap a partial in a IF/ELSE helper:
- The partial within the IF does not get variables passed
- When ELSE is triggered but does not render the content within.
If I remove the IF/ELSE helper no such behaviour occurs.
tpl.js:
Template7.registerHelper('ifFlipped', function (key, options) {
// isVisible() does check via a data model
if (typeof key === 'function') key = key.call(this);
if (isVisible(key)) {
options.fn(this, options.data);
}
else {
options.inverse(this, options.data);
}
});
Template7.registerPartial('inboxInvite', $$('script#tpl_inbox_invite').html());
Template7.registerPartial('isFlipped', $$('script#tpl_is_flipped').html());
Template7.registerPartial('notFlipped', $$('script#tpl_not_flipped').html());
tpl.html:
<script id="tpl_inbox_invite" type="text/template7">
<h2>Does not work<h2/>
{{#ifFlipped @key}}
<div class="card-outer is-flipped">
<b>Has no variables</b>
{{> "isFlipped"}}
</div>
{{else}}
<b>Does not show</b>
{{> "notFlipped"}}
{{/ifFlipped}}
<h2>Does work<h2/>
<b>Does show and has variables</b>
{{> "isFlipped"}}
</script>
<script id="tpl_is_flipped" type="text/template7">
<div class="card">Flipped but you do not see me</div>
</script>
<script id="tpl_not_flipped" type="text/template7">
<div class="card">Not flipped but you do not see me</div>
</script>
inbox.html
<template>
{{#each _invitesInbox}}
{{> "inboxInvite"}}
{{/each}}
</template>
<script>
return {
data: function () {
return {
'_invitesInbox': {
'123' : { one : 1, two : 2},
'321' : { one : 2, two : 4}
}
}
}
</script>
model.js:
function isVisible(key){
return (key == '123');
}
I might be missing something obvious. I’m using an older version of Framework7 (4.5.2) I think it should not matter as it all-ready includes the latest Template7 (1.4.2)
Thanks for this great framework! And if there are any thoughts that would be very much appreciated.