【问题标题】:Iron-router and Meteor : Template rendering on different urlIron-router 和 Meteor:不同 url 上的模板渲染
【发布时间】:2014-01-03 20:40:20
【问题描述】:

我有 3 个模板。注册、登录和公共模板。

有没有一种方法可以让把手执行这样的逻辑来获取 url 并呈现模板?

喜欢:

{{#if currentPage 'public'}}
  render public template
{{elseif currentPage 'login'}}
  render login template
{{else}}
  render signup template
{{/if}}

【问题讨论】:

  • 这些页面应该有单独的路由,并且每个路由都应该指定您要用于该页面的模板。
  • 他们有分开的路线,但他们在一页。

标签: meteor handlebars.js iron-router


【解决方案1】:

我不认为包中有一个助手可以做到这一点,但注册一个很容易:

UI.registerHelper("currentPage", function(localPath) {
    return Router.current(true).path === localPath;
});

您也可以将其注册为给定模板的帮助程序,但以上将允许全局访问它。

请注意,您需要提供带有前导 / 的参数才能使其正常工作,例如 /public、/login 等。

【讨论】:

    猜你喜欢
    • 2015-12-22
    • 2014-01-16
    • 2013-11-23
    • 2023-03-30
    • 2015-03-06
    • 1970-01-01
    • 2015-06-23
    • 2015-05-24
    • 1970-01-01
    相关资源
    最近更新 更多