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

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

问题描述

处理流星中多个页面"的正式"方式是什么?我说的是页面",我见过人们用几种不同的方式来做到这一点.我见过人们创建实际的完整页面(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.

推荐答案

有几种方法可以处理流星中的多个页面

There are several ways to handle multiple pages in meteor

使用铁路由器,您可以创建布局模板,并使用{{> yield}}将所有其他模板注入其中.查看铁路由​​器指南,以了解有关布局模板的更多信息.

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.

如果不想添加Iron-Router,则可以使用{{> 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");
  }
  // ..
});

如果会话返回关于", {{> Template.dynamic template="about"}}等效于{{> about}}.

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

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

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