Reputation:
I have a JSF page which include <head>...</head>
from another page. Basically it's looks like this:
<ui:include src="/path/head.xhtml"/>
<h:body>
...
</h:body>
I want to add unique <meta name="description" content="Unique content">
to each page which use <ui:include src="/path/head.xhtml"/>
.
I have 2 ideas:
<meta name="description".../>
to head-page and overwrite it on include-pages?<meta.../>
from include pages to head?Upvotes: 1
Views: 385
Reputation: 1108567
Several ways:
Use <ui:insert>
without name
and have body of <ui:include>
override it:
/WEB-INF/includes/head.xhtml
<h:head>
...
<ui:insert>
<meta name="description" content="Default description" />
</ui:insert>
...
</h:head>
/page.xhtml
<ui:include src="/WEB-INF/includes/head.xhtml">
<meta name="description" content="Overridden description" />
</ui:include>
Use <ui:insert>
with name
, and use <ui:decorate><ui:define>
instead of <ui:include>
:
/WEB-INF/includes/head.xhtml
<h:head>
...
<ui:insert name="description">
<meta name="description" content="Default description" />
</ui:insert>
...
</h:head>
/page.xhtml
<ui:decorate template="/WEB-INF/includes/head.xhtml">
<ui:define name="description">
<meta name="description" content="Overridden description" />
</ui:define>
</ui:decorate>
Simply use <ui:param>
with solely the meta content to keep code DRY when you already have a default description:
/WEB-INF/includes/head.xhtml
<h:head>
...
<meta name="description" content="#{empty description ? 'Default description' : description}" />
...
</h:head>
/page.xhtml
<ui:include src="/WEB-INF/includes/head.xhtml">
<ui:param name="description" value="Overridden description" />
</ui:include>
Upvotes: 3