Opencms JSP Template Development-create a JSP template containing multiple editable Elements

Source: Internet
Author: User

In the previous article, we have learned how to create a JSP template containing the "head" area and "foot" area. Now we will expand this template, add multiple editable page elements.
First, add the "<CMS: editable>" tag to the HTML head tag of the template file and add the "editable" attribute to the page element. The Code is as follows:

<% @ Taglib prefix = "CMS" uri = "http://www.opencms.org/taglib/cms" %>
<CMS: Template element = "head">
<HTML>
<Head>
<Title>
<CMS: property name = "title"/> </title>
<Meta HTTP-EQUIV = "Content-Type" content = "text/html; charset = <CMS: property name =" content-encoding "default =" UTF-8 "/>"/>
<LINK rel = "stylesheet" type = "text/CSS" href = "<CMS: link> ../resources/mystyle.css </CMS: link>"/>
<CMS: editable/>
</Head>
<Body>
<H2> head of the first simple template </H2>
</CMS: Template>
<CMS: Template element = "body">
<CMS: Include element = "body" editable = "true"/>
</CMS: Template>
<CMS: Template element = "foot">
<H2> foot of the first simple template </H2>
</Body>
</Html>
</CMS: Template>

Use this template to generate a page. The effect is as follows: the "body" element is now an area that can be directly edited. An "edit" button is displayed on the right of the editing area, click the "edit" button to directly go to the editor and edit the content of the "body" element. You do not have to find resources in the workspace as before, and click resources, in the pop-up menu, select "Edit page" for editing. In contrast, it is much easier.

The following is an extension of this template. add multiple elements to the template. The Code is as follows:

<% @ Taglib prefix = "CMS" uri = "http://www.opencms.org/taglib/cms" %>
<CMS: Template element = "head">
<HTML>
<Head>
<Title>
<CMS: property name = "title"/> </title>
<Meta HTTP-EQUIV = "Content-Type" content = "text/html; charset = <CMS: property name =" content-encoding "default =" UTF-8 "/>"/>
<LINK rel = "stylesheet" type = "text/CSS" href = "<CMS: link> ../resources/mystyle.css </CMS: link>"/>
<CMS: editable/>
</Head>
<Body>
<H2> head of the first simple template </H2>
</CMS: Template>
<CMS: Template element = "body"> <H2> This is the first page element </H2>
<CMS: Include element = "body" editable = "true"/> <CMS: Template ifexists = "body2">
<H2> This is the second page element </H2>
<CMS: Include element = "body2" editable = "true"/>
</CMS: Template>

</CMS: Template>
<CMS: Template element = "foot">
<H2> foot of the first simple template </H2>
</Body>
</Html>
</CMS: Template>

Next, we need to set the template file to "tell" the editor. This template can display two page elements and modify the "template-elements" attribute of the template file, set the value to "body * | element 1, body2 * | element 2". The element name ends, after "|" is the name of the element displayed in the editor, the editor will know the page generated using this template, it contains two editable elements, "element 1" and "element 2". The browsing effect is as follows:

Use this template to generate a page. The browsing effect is as follows. You can see that there are two editable elements.

Now, we know how to create a template that contains multiple editable elements. We can flexibly apply it to the project. This "direct editing" method is used, it is not only intuitive and easy to operate, but our customers will also like it very much.
(Thank you for choosing opencms-the first blog in Chinese resources. You are welcome to directly communicate with the author and make progress together. MSN: qianxuncms@hotmail.com, QQ: 9165456)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.