2014-01-21 8 views
0

글쎄, 내 애플 리케이션을위한 동적 메타 태그를 가지고 메신저 - 블로그를 만드는 메신저 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했던 한 여기 i'v이 무슨 짓입니다 :

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 
      } 
     } 
    }); 

이 동적 경로를 잘못하면 게시물의 문서 제목이 삽입됩니다. 세그먼트 (findOne by ID) 현재 게시물 제목을 반환합니다. 아쉽게도이 간단한 패키지를 패키지로 만들지는 않습니다. 비슷한 패키지를 대기에서 보지 못했습니다. 여러분이 도움이되기를 바랍니다.