嗯,我需要一些方法来有一个动态元标签为我的应用程序,我创建了一个cms-blog,所以我需要改变的meta 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
});因此,如果客户端路由到"/“,并且Posts集合持有id为"/”的帖子,而文档持有metaTitle:“Post1”,那么这是否会继续到template.post.metaTitle助手,标题将是“Post1”?
有没有更好的方法?
并做类似的事情,关键字等。
发布于 2014-01-22 06:48:25
好的,我已经做了这件事,这是我所做的:
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>路由器(iron- 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,如果我做这个动态路径段(按ID的findOne ),它将返回当前的帖子标题,我想我会让这个简单的东西成为一个包,我还没有在atmosphere中看到过类似的包。希望对你们有帮助。
https://stackoverflow.com/questions/21269282
复制相似问题