meteor - Template.body vs Template.myTemplate -
i going through meteor tutorial (https://www.meteor.com/try), , have come across templates puzzles me.
in tutorial, simple "todo list" application gets created. in app, following html placed simple-todos.html file:
<!-- simple-todos.html --> <head> <title>todo list</title> </head> <body> <div class="container"> <header> <h1>todo list</h1> </header> <ul> {{#each tasks}} {{> task}} {{/each}} </ul> </div> </body> <template name="task"> <li>{{text}}</li> </template>
then, following javascript placed simple-todos.js file:
// simple-todos.js tasks = new mongo.collection("tasks"); if (meteor.isclient) { // code runs on client template.body.helpers({ tasks: function () { return tasks.find({}); } }); }
at point, example works intended. however, poke around in documentation, @ other examples on web, have noticed different syntax: using template.mytemplate instead of template.body.
so, out of curiosity, altered javascript file read:
template.task.helpers({ ...
instead of:
template.body.helpers({ ...
however, when run application now, client not display data collection. don't errors undefined types, if misspell template name in javascript, seems resolving template correctly. why isn't getting used or rendered?
and go little further: when appropriate use template.mytemplate , when appropriate use template.body?
the helpers code works template it's attached too.
so, code works template.task
apply templates named "task".
template.body one-off exists because weird if didn't. it's way target <body>
, though technically, there's no template named "body".
so, going on:
- parent template = body
- child template = task
your logic says:
in parent template, each task find, render instance of child template "task".
if change helper body
task
, won't output @ all, unless mimic pattern that's happening:
<template name="task"> {{#each tasks}} {{/each}} </template>
Comments
Post a Comment