<!--[如果 IE]>条件注释在 Facelets 中呈现为 HTML 转义 [英] <!--[if IE]> conditional comments are rendered HTML-escaped in Facelets
问题描述
我正在尝试使用 IE 条件注释来声明 CSS 资源:
I'm trying to use an IE conditional comment to declare a CSS resource:
<h:outputStylesheet name="common.css" library="css" />
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="#{resource['css:ie.css']}" />
<![endif]-->
然而,这似乎不起作用.我在生成的 HTML 输出中看到了这一点:
However, that doesn't seem to work. I'm seeing this in my generated HTML output:
<link type="text/css" rel="stylesheet" href="/context/faces/javax.faces.resource/common.css?ln=css" />
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="/context/faces/javax.faces.resource/ie.css?ln=css"/>
<![endif]-->
它在没有条件注释的情况下工作正常.我没有使用上下文参数 javax.faces.FACELETS_SKIP_COMMENTS
.这是怎么引起的,我该如何解决?
It works fine without the conditional comment. I'm not using the context parameter javax.faces.FACELETS_SKIP_COMMENTS
. How is this caused and how can I solve it?
推荐答案
这确实不起作用,因为 Facelets 隐式地对注释的内容进行 HTML 转义.最好的办法是将它放在
中,如下所示:
This indeed won't work as Facelets implicitly HTML-escapes the comment's contents. Your best bet is to put it in a <h:outputText escape="false">
as follows:
<h:outputText value="<!--[if IE]><link rel="stylesheet" type="text/css" href="/#{resource['css:ie.css']}" /><![endif]-->" escape="false" />
然而,这是一条丑陋的线.OmniFaces JSF 实用程序库有一个
正是为了这个目的:
This is however a line of ugliness. The OmniFaces JSF utility library has a <o:conditionalComment>
for exactly this purpose:
<o:conditionalComment if="IE">
<link rel="stylesheet" type="text/css" href="#{resource['css:ie.css']}" />
</o:conditionalComment>
<小时>
与具体问题无关,您没有真正以正确的方式使用 library
属性.它应该标识一个共同的主题",而不是放置文件的子文件夹,只需将该子文件夹放在 name
属性中即可.另请参见 什么是 JSF资源库用于以及如何使用?
Unrelated to the concrete problem, you are not really using the library
attribute the right way. It should identify a common "theme", not the subfolder where the files are placed in, just put that subfolder in the name
attribute instead. See also What is the JSF resource library for and how should it be used?
<h:outputStylesheet name="css/common.css" />
<o:conditionalComment if="IE">
<link rel="stylesheet" type="text/css" href="#{resource['css/ie.css']}" />
</o:conditionalComment>
这篇关于<!--[如果 IE]>条件注释在 Facelets 中呈现为 HTML 转义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!