如何使用页眉/页脚/导航创建可重复使用的模板?

编程入门 行业动态 更新时间:2024-10-24 01:54:38
本文介绍了如何使用页眉/页脚/导航创建可重复使用的模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在与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="www.w3/1999/xhtml" xmlns:f="java.sun/jsf/core" xmlns:h="java.sun/jsf/html" xmlns:ui="java.sun/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="www.w3/1999/xhtml" xmlns:f="java.sun/jsf/core" xmlns:h="java.sun/jsf/html" xmlns:ui="java.sun/jsf/facelets" > <ui:define name="title">hello</ui:define> <ui:define name="content"> Hi, this is the page </ui:define> </ui:composition>

更多推荐

如何使用页眉/页脚/导航创建可重复使用的模板?

本文发布于:2023-11-16 22:02:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607647.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:页眉   如何使用   重复使用   模板   页脚

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!