我有基于JSF的页面的以下主模板文件:
<!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"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title><ui:insert name="title">MyApp</ui:insert></title>
<h:outputStylesheet name="stylesheet.css" library="styles"/>
</h:head>
<h:body>
<div id="container">
<div id="header">
<ui:insert name="header">
// header content
</ui:insert>
</div>
<div id="content">
<ui:insert name="content">
</ui:insert>
</div>
<div id="footer">
<ui:insert name="footer">
</ui:insert>
</div>
</div>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
在头部,我们有stylesheet.css.此样式表包含所有页面共有的全局样式.
在模板客户端中,我想添加页面特定的样式表.所以,我尝试在我的模板客户端页面中添加以下行:
<ui:composition template="/pages/templates/template.xhtml">
<ui:define name="content">
<h:outputStylesheet name="indexPage.css" library="styles" target="head"/>
// body content
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
但是,这似乎没有添加indexPage.css到生成的HTML头部.
我正在使用Mojarra 2.1.2.它是否支持该target属性?我没有看到它被列为Eclipse中我的autosuggest选项中的可用选项之一.
如果没有,如何在仍使用模板的同时注入额外的页面特定CSS?
在head部分新模板内容中添加到主模板文件,专门用于css文件链接:
<h:head>
<title><ui:insert name="title">MyApp</ui:insert></title>
<h:outputStylesheet name="stylesheet.css" library="styles"/>
<ui:insert name="css"/>
</h:head>
Run Code Online (Sandbox Code Playgroud)
在模板客户端页面中添加如下页面特定的样式表:
<ui:composition template="/pages/templates/template.xhtml">
<ui:define name="css">
<h:outputStylesheet name="indexPage.css" library="styles"/>
</ui:define>
...
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
而不是使用h:outputStylesheetcoud <link rel="stylesheet" type="text/css" href="relative path to css file">.重要的是,主模板中ui:insert的css应该在里面h:head.
| 归档时间: |
|
| 查看次数: |
8680 次 |
| 最近记录: |