处理多个“页面"的正确方法在流星 [英] Proper way to handle multiple "pages" in meteor

查看:32
本文介绍了处理多个“页面"的正确方法在流星的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在meteor 中处理多个页面"的正式"方式是什么?我说页面"我见过人们用几种不同的方式来做.我见过人们创建实际的完整页面(index.html、about.html、contact.html),然后当点击链接时,您会编写一个路由来呈现这些页面.但我也看到人们基本上将每个页面的代码放在 <template> 标签中,然后根据他们点击的内容、登录凭据等进行漂亮的显示/隐藏类型的内容.

What is the "formal" way of handling multiple "pages" in meteor? I say "pages" I've seen people do it a couple of different ways. I've seen people create actual full pages, (index.html, about.html, contact.html) and then when links are clicked, you'd write a route to render those pages. But I've also seen people essentially put the code for each of those pages inside <template> tags and then do nifty show/hide type stuff based of what they've clicked, login credentials, etc.

推荐答案

meteor中处理多个页面的几种方式

There are several ways to handle multiple pages in meteor

使用铁路由器,您可以创建布局模板并使用 {{>产量}}.查看 iron-router 指南以了解有关布局模板的更多信息.

using iron router you can create a layout template and inject all other templates inside it using {{> yield}}. Check the iron-router guide to know more about layout template.

如果你不想添加铁路由器,你可以使用 {{>Template.dynamic}} 实现相同.

if you do not want to add iron-router you can use {{> Template.dynamic}} to achieve the same.

<body>
  <ul>
    <li><a href="#" class="index">Home</li>
    <li><a href="#" class="about">About</li>
    <li><a href="#" class="contact">Contact</li>
  </ul>
  {{> Template.dynamic template=template_name }}
</body>

template_name 可以使用模板助手进行被动更改

template_name can be changed reactively using a template helper

Meteor.startup(function () {
  Session.setDefault("templateName", "index")
});

Template.body.helpers({
  template_name: function(){
    return Session.get("templateName")
  }
});

Template.body.events({
  "click .home": function() {
    Session.set("templateName", "index");
  },
  "click .about": function() {
     Session.set("templateName", "about");
  }
  // ..
});

如果会话返回about"然后,<代码>{{>Template.dynamic template="about"}} 相当于 {{>;关于}}.

If the Session returns "about" then, {{> Template.dynamic template="about"}} which is equivalent to {{> about}}.

这篇关于处理多个“页面"的正确方法在流星的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆