2014-01-21 30 views
0

嗯,我需要一些方法來爲我的應用程序有一個動態的meta標籤,即時通訊創建一個cms博客,​​所以生病需要改變元desc /關鍵字/標題等在每一個職位,路由器。 我有一個想法如何做到這一點用沒有完全確定:流星動態元標籤

<template name="post"> 
{{metaTitle}} 
</template> 

Template.post.metaTitle = function (this) { 
    document.title = this; 
} 

(鐵路由器版本)

this.route('post', { 
     path: '/', 
.... 
data: function() { 
return Posts.findOne({_id: this.params._id}); 
} 
//Posts holds post documents with a fields like: "metaTitle" "metaKeywords" etc 
}); 

因此,如果一個客戶端路由到「/」和帖子收集任職ID爲「/」 且文檔中包含metaTitle:「Post 1」 這將繼續執行template.post.metaTitle幫手 並且標題將爲「Post 1」?

有沒有更好的方法?

,並做類似的東西的關鍵字等

回答

0

好吧,我有manged要做到這一點,這裏是我心中已經做了什麼:

HTML:

<template name="posts"> 

    {{metaTitle}} 
    {{metaDesc}} 
    {{metaKeywords}} 

    {{>home}} 

    {{#each posts}} 
    </div> 
    <a href="{{pathFor 'post'}}"> 
     <div class="small-12 medium-12 large-12 columns"> 
      <div class="post"> 
       <div class="small-12 medium-12 large-12 columns"> 
        <h4 class="left">{{author}}</h4> 
        <h4 class="right">{{date}}</h4> 
       </div> 
       <h2>{{title}}</h2> 
       <p>{{desc}}</p> 
      </div> 
     </div> 
    </a> 
    <hr/> 
    {{/each}} 
</template> 

路由器(鐵-router):

this.route('posts', { 
     path: '/', 

     waitOn:function(){ 
      NProgress.start(); 
      Meteor.subscribe("Teams"); 
     }, 

     before: function() { 
      Session.set("adding_group", false); 
      NProgress.done(); 
      /* 
      causes problems when phonegap mode 
      */ 
     }, 

     fastRender:true, 

     unload: function() { 
      Session.set("adding_group", true); 
      Session.set("group_name", false); 
      Session.set("group_date", false); 
      Session.set("group_friends", false); 
      Session.set("group_location", false); 
      Session.set("group_rules", false); 
      Session.set("group_desc", false); 
      Session.set("group_save", false); 
     }, 
     yieldTemplates: { 
      'nav': {to: 'header'} 
     }, 

     data:{ 
      posts:Posts.find({}), 
      metaTitle:function(){ 
       var one = Posts.findOne({}); //just for the example 
       return document.title = one.title; //just for the example 
      } 
     } 
    }); 

這將插入帖子的document.title時,如果生病做動態路徑分段 (findOne by ID)它將返回當前帖子標題, 我認爲生病使這個簡單的東西成爲一個包,我還沒有看到類似的包在氣氛。 希望它可以幫助你們。