如何使用页眉/页脚/导航创建可重复使用的模板? [英] How to create a reuseable template with header/footer/navigation?

查看:91
本文介绍了如何使用页眉/页脚/导航创建可重复使用的模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在与JSF一起玩,并且有一个包含页眉/页脚/导航/内容的项目 面板.但是,该项目从第1页转到第2页,依此类推,每个页面都有不同的布局.如何创建可重复使用的模板,使页面之间的外观保持相同,即页眉/页脚/导航保持不变,但内容已更新?

I have been playing with JSF and have a project working that has a header/footer/navigation/content panels. The project, however, goes from page 1 to page 2, etc., with each page having a different layout. How can I create a reusable template that keeps the same look and feel from page to page, i.e., header/footer/navigation stay the same, but content is updated?

推荐答案

这听起来像是主模板的经典案例.在这样的模板中,您放置了所有页面共有的所有内容,然后您的实际页面引用了该模板并填入空白".在某种程度上,它与经典的include相反.

This sounds like a classic case of a master template. In such a template you put everything that's common to all pages and then your actual pages reference this template and "fill in the blanks". In a way it's the reverse of the also classic include.

例如

/WEB-INF/templates/masterTemplate.xhtml:

<!DOCTYPE html>
<html lang="en"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets" 
>
    <h:head>
        <title>
            <ui:insert name="title">Some title</ui:insert>
        </title>        
    </h:head>

    <ui:include src="header.xhtml"/>

    <h:body>
        <ui:insert name="content" />
    </h:body>

    <ui:include src="footer.xhtml"/>

</html>

页面按如下方式使用它,例如

A page uses this as follows, e.g.

/hello.xhtml

<ui:composition template="/WEB-INF/templates/masterTemplate.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets" 
>
   <ui:define name="title">hello</ui:define>

    <ui:define name="content">
        Hi, this is the page
    </ui:define>
</ui:composition>

这篇关于如何使用页眉/页脚/导航创建可重复使用的模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆