如何通过URL将Meteor模板提供给目标受众? [英] How can I make Meteor templates available to targeted audiences via an URL?

查看:76
本文介绍了如何通过URL将Meteor模板提供给目标受众?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Meteor建立各种Blog,但我不只是拥有platypus.meteor.com之类的Blog,而是想为每个Blog"post"创建一个单独的Meteor模板,然后发送链接选择"platypus.meteor.com/thispost"之类的人

I want to build a Blog, of sorts, with Meteor but, rather than just have a Blog such as platypus.meteor.com, I want to create a separate Meteor template for each Blog "post" and then send a link to select people such as "platypus.meteor.com/thispost"

这样,此人只会看到我希望他们看到的帖子;要看到其他人,他们将不得不猜测其他值,例如"/thatpost","/theotherpost"等.

In this way, the person would only see the post I intend them to see; to see others, they would have to guess at other values, such as "/thatpost", "/theotherpost" etc.

就我而言,如果他们偶然发现了它们,那没什么大不了的.

And in my case, if they stumbled across them, no big deal.

这是我的计划

一次创建一个模板:

<template name="thispost">
    . . .
</template>

...然后允许我向其提供此信息的任何人访问该文件(也就是说,他们只需将我发送给他们的链接输入到他们的浏览器中即可).

...and then allow access to that to whomever I apprise of its availability (that is, they simply enter the link I send them into their browser).

我不知道我需要设置哪种路由;我对IronRouter或FlowRouter开放.无论如何,我希望像"platypus.meteor.com/thispost"这样的URL(在此项目的流星部署platypus"之后)向用户显示该模板的内容,而没有其他内容.

I don't know what sort of routing I need to set up; I'm open to either IronRouter or FlowRouter. At any rate, I want an URL like "platypus.meteor.com/thispost" (after a "meteor deploy platypus" of this project) to show the user the contents of that Template and nothing else.

所以我的问题是:要完成此操作,我必须做些什么?

So my question is: what do I have to do, routing-wise, to accomplish this?

推荐答案

简单地说:

Router.route("/:templateName/:postId",{
  template: this.params.templateName,
  data: function(){ return Posts.findOne({ _id: this.params.postId })
});

然后,您可以与任何模板通用地共享任何帖子,并使模板名称显示在路线中.

Then you can generically share any post with any template and have the template name appear right in the route.

这篇关于如何通过URL将Meteor模板提供给目标受众?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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