如何访问流星设置文件

时间:2019-02-28 04:05:20

标签: meteor

是否可以访问client/main.html文件中的设置文件。在应用程序中,我可以使用{Meteor.settings.public.appName}来使用,但是在此文件中不起作用,我不确定为什么。

路径:client/main.html

<head>
  <title>{Meteor.settings.public.appName}</title>
</head>

<body>
  <div id="react-target"></div>
</body>

2 个答案:

答案 0 :(得分:0)

您编写的内容不是有效的html,并且您也不位于Blaze模板内。这样就行不通了。

您可以在blaze模板中访问这些对象,例如:

<template name="mytemplate">
  {{Meteor.settings.public.appName}}
</template>

,但是页面的head不能是模板。另外,似乎您打算使用React而不是Blaze,因此您需要编写一个React组件。但是您可以在其中轻松访问设置(就像您范围中的任何其他变量一样),例如:

class MyComponent extends React.Component {
  render() {
    return (<div>
        My app is called: {Meteor.settings.public.appName}
      </div);
  }
}

答案 1 :(得分:0)

解决方案是使用@Pual Paulincai建议的react头盔。

https://github.com/nfl/react-helmet