我是流星的新手。下面是来自Metronics前端模板的一小部分代码:
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->我只知道Meteor自己插入了一些HTML代码,并且禁止手动执行。有人能指导我如何在我的模板中插入上述代码吗?
发布于 2014-06-18 09:46:21
更新
检查注射-初始包,它允许您在发送之前修改HTML。
无趣的方式:
Meteor不支持自定义doctype或html注释。
但是,如果您可以用包含更新的boilerplate.html的分叉版本替换WebApp包,那么这应该是可行的,但它将被黑客攻击。
WebApp包
boilerplate.html:
<html {{htmlAttributes}}>
<head>
...
</head>
<body>
{{{body}}}
</body>
</html>来源:https://github.com/meteor/meteor/blob/devel/packages/webapp/boilerplate.html
webapp_server.js (第490至497行):
var boilerplateData = _.extend({htmlAttributes: htmlAttributes},
boilerplateBaseData);
var boilerplateInstance = boilerplateTemplate.extend({
data: boilerplateData
});
var boilerplateHtmlJs = boilerplateInstance.render();
boilerplateByAttributes[attributeKey] = "<!DOCTYPE html>\n" +
HTML.toHTML(boilerplateHtmlJs, boilerplateInstance);来源:server.js
发布于 2015-02-03 10:47:00
在流星中添加以下内容:
<head>
<!--[if IE 8]> <meta name="ie-8"> <![endif]-->
<!--[if IE 9]> <meta name="ie-9"> <![endif]-->
<!--[if IE]> <meta name="is-ie"> <![endif]-->
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1" name="viewport"/>
<meta content="" name="MyApp"/>
<meta content="" name="MyCompany"/>
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css"/>
</head>您可以创建一个新的html文件,或者将上面的内容添加到现有的模板中。
接下来,将以下内容添加到模板助手咖啡/js文件中:
Template.hello.rendered = ->
$('html').attr 'lang', 'en'
if $('meta[name=\'ie-8\']').length
$('html').attr 'class', 'ie8'
$('head').append '<meta content="" name="ie8"/>'
if $('meta[name=\'ie-9\']').length
$('html').attr 'class', 'ie9'
$('head').append '<meta content="" name="ie9"/>'
if $('meta[name=\'is-ie\']').length
$('head').append '<meta content="" name="is-ie"/>'
else
$('head').append '<meta content="" name="not-ie"/>'
return在模板呈现之后,这将搜索meta:name并做出相应的反应。您可以向html添加属性,也可以向头部添加内容。
根据流星文献:
http://docs.meteor.com/#/full/structuringyourapp
Meteor应用程序中的HTML文件与服务器端框架有很大不同。Meteor扫描目录中的所有HTML文件中的三个顶级元素:、和。头和体部分分别连接成一个单独的头和主体,这些头和体在初始页面加载时传送给客户端。
上述结果将是:
<head>
<link rel="stylesheet" type="text/css" class="__meteor-css__" href="/6176b8b829c9df965e358642efa91f9fb2d91b51.css">
<script type="text/javascript">__meteor_runtime_config__ = {"meteorRelease":"METEOR@1.0.3.1","ROOT_URL":"http://localhost:3000/","ROOT_URL_PATH_PREFIX":"","appId":"reg9gp1tr7xjw1ia7u0e","autoupdateVersion":"a00b33a70d60e865c9f096b9c3e8a9f5386ed45c","autoupdateVersionRefreshable":"79d3c80e832e7e5b97b84f80da47f9571b97f8a7","autoupdateVersionCordova":"none"};</script>
<script type="text/javascript" src="/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18"></script>
...
<title>Meteor App</title>
<!--[if IE 8]> <meta name="ie-8"> <![endif]-->
<!--[if IE 9]> <meta name="ie-9"> <![endif]-->
<!--[if IE]> <meta name="is-ie"> <![endif]-->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1" name="viewport">
<meta content="" name="Agent Online">
<meta content="" name="Online Travel Services AG">
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css">
<meta content="" name="not-ie">
</head>https://stackoverflow.com/questions/24279360
复制相似问题