【发布时间】:2010-10-04 04:09:57
【问题描述】:
来自 Django 的背景,我经常使用“模板继承”,其中多个模板继承自一个公共基础。在 JSP 中是否有一种简单的方法可以做到这一点?如果没有,是否有替代 JSP 的方法(除了 Jython 上的 Django 之外:)
基本模板
<html>
<body>
{% block content %}
{% endblock %}
</body>
<html>
基本内容
{% extends "base template" %}
{% block content %}
<h1>{{ content.title }} <-- Fills in a variable</h1>
{{ content.body }} <-- Fills in another variable
{% endblock %}
会呈现如下(假设conten.title为“Insert Title Here”,content.body为“Insert Body Here”)
<html>
<body>
<h1>Insert title Here <-- Fills in a variable</h1>
Insert Body Here <-- Fills in another variable
</body>
<html>
【问题讨论】: