Skip to content

Instantly share code, notes, and snippets.

@wasbazi
Last active December 31, 2015 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wasbazi/7953890 to your computer and use it in GitHub Desktop.
Save wasbazi/7953890 to your computer and use it in GitHub Desktop.
Window vs. Template scope in Meteor
<head>
<title>MeteorGame</title>
</head>
<body>
{{> game}}
</body>
<template name="game">
<h1>Hello World!</h1>
<input type="type" id="hidden-input">
<div id="game"></div>
<div id="output">
{{> newCharacter}}
</div>
</template>
<template name="newCharacter">
<h5>Select a character</h5>
<div id="character-viewer">
<div
class="character"
style="{{heroPosition}}"></div>
</div>
<div id="character-selector">
{{#forEach characters}}
<div
class="character {{selectedClass _key}}"
style="{{backgroundPosition}}"></div>
{{/forEach}}
</div>
</template>
<script>
//other stuff
Template.newCharacter.heroPosition = function(){
// this == Window
var character = Template.newCharacter.characters[module.getSelectedIdx()];
var charCoords = Template.newCharacter.backgroundPosition.call(character, null, 4);
return charCoords;
};
// other stuff
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment