Last active
April 21, 2018 11:52
-
-
Save harrylove/4381571 to your computer and use it in GitHub Desktop.
Nested template problem, deployed to http://nestedtemplate.meteor.com/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<title>conditional templates</title> | |
</head> | |
<body> | |
Open the console. Session.set('active') to 'foo' or 'bar'. Then set the foo contents with Session.set('fooContents') to 'foofoo' and 'foobar'. Set bar contents with Session.set('barContents') to 'barfoo' or 'barbar', respectively. | |
{{> main }} | |
</body> | |
<template name="main"> | |
{{{ contents }}} | |
</template> | |
<template name="foo"> | |
<h2>Foos</h2> | |
{{ contents }} | |
</template> | |
<template name="foofoo"> | |
The foo foos. | |
</template> | |
<template name="foobar"> | |
The foo bars. | |
</template> | |
<template name="barfoo"> | |
The bar foos. | |
</template> | |
<template name="barbar"> | |
The bar bars. | |
</template> | |
<template name="bar"> | |
<h2>Bars</h2> | |
{{ contents }} | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (Meteor.isClient) { | |
var getContainerContents = function() { | |
console.info('get container contents'); | |
var active = Session.get('active') == 'foo' ? 'foo' : 'bar'; | |
return Template[active](); | |
}; | |
Template.main.contents = function() { | |
return getContainerContents(); | |
}; | |
Template.foo.contents = function() { | |
console.info('foo contents'); | |
return fooContents(); | |
}; | |
var fooContents = function() { | |
var contents = Session.get('fooContents') == 'foo' ? 'foofoo' : 'foobar'; | |
return Template[contents](); | |
}; | |
Template.bar.contents = function() { | |
console.info('bar contents'); | |
return barContents(); | |
}; | |
var barContents = function() { | |
var contents = Session.get('barContents') == 'foo' ? 'barfoo' : 'barbar'; | |
return Template[contents](); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment