作者:王轩
Building a complete JSP template with multiple and direct editable page elements
建立有多个可以直接编辑的页面元素的JSP模板
In the previous step, you have created a complete JSP template with "head" and "foot" elements. Now we will use this template to make the page element content directly editable from the frontend and add multiple page elements on it.
在之前的步骤中,你已经建立了有Head Foot元素的完整JSP模板。现在我们将用这个Template建立可直接编辑的页面元素,并加入多个页面元素。
First, we must mark the template as "direct editable", this is done by adding the <cms:editable> tag to the HTML head in the template. The include of the page element itself must be extended with the editable attribute, both modifications are shown below.
首先,必须标记这个模板是可以"direct editable",方法是把<cms:editable>tag加入到模板的HTML head中。页面包含的页面元素
<%@ page session="false" %>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<cms:template element="head">
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>
<cms:property name="title" escapeHtml="true" />
</title>
<meta HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; CHARSET=<cms:property name="content-encoding" default="ISO-8859-1" />">
<link type="text/css" rel="stylesheet" href="<cms:link>../resources/mystyle.css</cms:link>">
<cms:editable />--在头中加入可直接编辑标记
</head>
<body>
<h2>My first template head</h2>
<!-- Main page body starts here -->
</cms:template>
<cms:template element="body">
<cms:include element="body" editable="true"/>--包含可以编辑body的标记
</cms:template>
<cms:template element="foot">
<!-- Main page body ends here -->
<h2>My first template foot</h2>
</body>
</html>
</cms:template>
The next extension is the use of multiple page elements in one template. With the <cms:template> tag, you can add control structures to the template which allows it to deal with multiple page elements.
另外一个扩展是在一个模板中使用多个页面元素,使用<cms:template> tag,通过给模板增加控制结构使模板允许处理多页面元素。
<%@ page session="false" %>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<cms:template element="head">
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>
<cms:property name="title" escapeHtml="true" />
</title>
<meta HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; CHARSET=<cms:property name="content-encoding" default="ISO-8859-1" />">
<link type="text/css" rel="stylesheet" href="<cms:link>../resources/mystyle.css</cms:link>">
<cms:editable />
</head>
<body>
<h2>My first template head</h2>
<!-- Main page body starts here -->
</cms:template>
<cms:template element="body">
<h2>This is the first page element:</h2>
<cms:include element="body" editable="true"/>
<cms:template ifexists="body2"> --问题,这个ifexist是个啥意思啊 难道是 if ,exists 如果存在
<h2>This is the second page element:</h2>
<cms:include element="body2" editable= "true"/>
</cms:template>
</cms:template>
<cms:template element="foot">
<!-- Main page body ends here -->
<h2>My first template foot</h2>
</body>
</html>
</cms:template>
As you can see, everything inside the tag will only be included in the output, if your page contains a page element named "body2". For a complete description of all possible control structures, see the documentation of the <cms:template> tag.
正如你看到的,如果你的页面包括为“body2”的页面元素,所有包含在tag中的元素将只包含在输出中。完整的控制结构的描述参见<cms:template> tag文档.
Now that you have modified the template itself, we must tell the editor, that the template can display a second page element as well. Therefore, you have to modifiy the value of the template-elements property of the template to: body*|Body,body2|2nd Body. Page elements that are mandatory are marked with a star "*", the string after the pipe "|" specifies the nice name of the element.
既然你修改了模板,就必须告诉编辑器,模板可能可以显示第二个页元素。因此,你必须修改模板的template-elements属性值,改为body*|Body,body2|2nd Body。Page elements that are mandatory are marked with a star "*", the string after the pipe "|" specifies the nice name of the element.
Congratulations! You have succeeded in creating your first "complete" OpenCms JSP template with direct edit and multiple pages.
Now proceed to the last step of the template howto to learn about JSP scriptlet options.