Proper way to handle multiple “pages” in meteor

前端 未结 1 1688
面向向阳花
面向向阳花 2021-01-02 10:18

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

相关标签:
1条回答
  • 2021-01-02 10:52

    There are several ways to handle multiple pages in meteor

    1.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.

    2.{{> 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 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");
      }
      // ..
    });
    

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

    0 讨论(0)
提交回复
热议问题