10
21
You can do similar things using JSP tag files. Create your own page.tag
that contains the page structure. Then use a <jsp:body/>
tag to insert the contents.
- [Django]-Django template includes slow?
- [Django]-What is the benefit of using a HyperlinkedModelSerializer in DRF?
- [Django]-Is the Lift framework as "easy" as Ruby on Rails or Django?
13
You can use rapid-framework for JSP template inheritance
base.jsp
%@ taglib uri="http://www.rapid-framework.org.cn/rapid" prefix="rapid" %>
<html>
<head>
<rapid:block name="head">
base_head_content
</rapid:block>
</head>
<body>
<br />
<rapid:block name="content">
base_body_content
</rapid:block>
</body>
</html>
child.jsp
<%@ taglib uri="http://www.rapid-framework.org.cn/rapid" prefix="rapid" %>
<rapid:override name="content">
<div>
<h2>Entry one</h2>
<p>This is my first entry.</p>
</div>
</rapid:override>
<!-- extends from base.jsp or <jsp:include page="base.jsp"> -->
<%@ include file="base.jsp" %>
output
<html>
<head>
base_head_content
</head>
<body>
<br />
<div>
<h2>Entry one</h2>
<p>This is my first entry.</p>
</div>
</body>
</html>
source code
- [Django]-Django in / not in query
- [Django]-Django print choices value
- [Django]-Restrict django FloatField to 2 decimal places
4
Other options worth exploring include Sitemesh, which is built on the idea of page decorators, and Java Server Faces (JSF), which employs web-based UI components. And while we’re talking about rapid development with web frameworks on the Java platform, I encourage you to check out Grails. It has the same mission has Django; namely, rapid web app development based on convention over configuration.
Hope that’s not too many suggestion for one post. :o)
- [Django]-Securing communication [Authenticity, Privacy & Integrity] with mobile app?
- [Django]-Django count RawQuerySet
- [Django]-Django Model – Get distinct value list
3
My favorite Java web front-end tech is Facelets. It supports the most Django-like templating I’ve seen. It’s not quite as clean as Django’s, but you get the same inheritance benefits.
Instead of Django’s:
Super:
{% block content %}{% endblock %}
Sub:
{% block content %}inheriting template's content here{% endblock %}
Facelet’s syntax is like this:
Super:
<ui:insert name="content"></ui:insert>
Sub:
<ui:define name="content">inheriting template's content here</ui:define>
- [Django]-ModuleNotFoundError: No module named 'grp' on windows
- [Django]-Migrating from django user model to a custom user model
- [Django]-Django import error – No module named core.management
1
Rythm Template engine has implemented an elegant approach for template inheritance.
So suppose your layout template (parent template) called main.html
:
<h1>@get("title", "default main page")</h1>
<div id="left-panel">@render("leftPanel")<div>
<div id="right-panel">@render("rightPanel")</div>
<div id="main-content">@render()</div>
<div id="footer">
@render("footer"){
@**
* the content here is supplied if the child template failed
* to provide it's own footer implementation
*@
<div class="footer">copyright 2012 ...</div>
}
</div>
And here is your target template:
@extends(main)
@set(title: "My Cool Page")
@section("leftPanel") {
<ul class="menu">
...
</ul>
}
@section("rightPanel") {
<div class="news">
...
</div>
}
@*** note no "footer" section supplied so the default content will be used **@
@*** the rest is for the main content **@
...
Check the real demo at http://rythmengine.com/demo/testdefaultlayoutcontent
A comprehensive document could be found at http://www.playframework.org/modules/rythm. Though it’s targeted to Play!Framework, most of the content also apply to pure rythm engine without Play!Framework.
- [Django]-Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually
- [Django]-How do I create a Django form that displays a checkbox label to the right of the checkbox?
- [Django]-How can I tell whether my Django application is running on development server or not?