[英]jquery templates - Templating a HTML page
I'm writing a tool to generate HTML pages using jquery templates, but it does not like certain tags (DOCTYPE, html, head). 我正在写一个使用jquery模板生成HTML页面的工具,但是它不喜欢某些标签(DOCTYPE,html,head)。 Is it possible to template something like this:
是否可以像这样模板化:
<script id="HtmlPageTemplate" type="text/x-jquery-tmpl">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>${PageTitle}</title>
<link rel="stylesheet" href="styles/style.css" type="text/css" media="all" />
<script src="scripts/script.js">{{html "</sc"+"ript>"}}
<script>
function MyFunction(){
}
{{html "</sc"+"ript>"}}
</head>
<body>
{{tmpl "#PageBody"}}
</body>
</html>
</script>
I'm using {{html "< /sc"+"ript>"}} to close script tags without closing the template script tag. 我正在使用{{html“ </ sc” +“ ript>”}}}关闭脚本标签而不关闭模板脚本标签。
I think this would be useful for you : 我认为这对您有用:
The basic idea is - replace '<' of all sensitive tag with some special mark, eg, '@#' and replace @# to '<'. 基本思想是-将所有敏感标签的'<'替换为某些特殊标记,例如'@#',然后将@#替换为'<'。 Use $.template() to compile the template.
使用$ .template()编译模板。 Finally, render.
最后,渲染。
<script id="HtmlPageTemplate" type="text/x-jquery-tmpl">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>${PageTitle}</title>
<link rel="stylesheet" href="styles/style.css" type="text/css" media="all" />
@#script src="scripts/script.js">@#/script>
@#script>
alert('here');
@#/script>
</head>
<body>
{{tmpl "#PageBody"}}
</body>
</html>
</script>
<div id="output"></div>
And replace the template using 并使用替换模板
$.template('test', $('#HtmlPageTemplate').html().split('@#').join('<'));
$.tmpl('test', data).appendTo($("#output"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.