ceth
ceth

Reputation: 45325

How can I split a template?

I have an HTML document:

<body>
    {{> today_list}}    
</body>

And template:

<template name="today_list">
   {{#if action_log_mode}}
   ...
   {{/if}}


   {{#if action_list_mode}}
   ...
   {{/if}}
</template>

Is it possible to split this template to two others. Something like this:

<body>
  {{#if action_log_mode}}
    {{> one}}
  {{/if}}   
  {{#if action_list_mode}}
    {{> two}}
  {{/if}}   
</body>

Upvotes: 0

Views: 68

Answers (1)

emgee
emgee

Reputation: 1234

You can have any number of templates, and they may be nested. They may be in the same, or different .html files.

I don't know without testing whether or not you can scope a template helper in body (outside a template). Template helpers are scoped to a specific template. 'one', for example, Template.one.listItem = function () { ... will not be accessible in template 'two'. However, you can add a global helper (which might work in <body>), like so (taken from the Meteor wiki):

Handlebars.registerHelper("foo", function() {
  return "blah"; // (calculate value here)
});

What absolutely would work is:

In app.html

<body>
  {{ > page }}
</body>

<template name="page">
   {{#if isLogMode}}
     {{ > one }}
   {{else}}
     {{ > two }}
   {{/if}}
</template>

<template name="one">
  ...
</template>

<template name="two">
  ...
</template>

In app.js

Template.page.isLogMode = function () {
  // (something like)
  return Session.get('logMode') === "log";
};

Upvotes: 1

Related Questions