In this post, I’ll demonstrate OFBiz CMS(Content Management System) uses for static pages on a website(front end application) through simple content data setup. CMS gives users the flexibility to change the content to be shown on static pages of your website.
All the features mentioned here are supported by the out-of-the-box (OOTB) OFBiz CMS implementation.
In this exercise you will:
- see the basic concept of DataResource and Content.
- setup content data to embed FTL markup.
- setup a content driven screen and use it to show the static content setup through data.
• Assumption: a component is already setup; here we are using the component name as “cmsdemo”.
DataResource and Content records
Let’s suppose that you want to define content (that will be included in a screen) for showing the text “This is the text that will appear on the screen.”.
Data Resource type- ELECTRONIC_TEXT
First of all, you have to define a DataResource representing this text. This gives you greater flexibility because you can store long texts in the textData field. If you want to embed FTL markup (directives etc…) that needs to be processed before rendering, you can achieve this using the dataTemplateTypeId attribute. This way all the Freemarker instructions in the text will be executed before rendering the screen. Following data needs to be setup in an XML data file:
<DataResource dataResourceId="DS-01" dataResourceTypeId="ELECTRONIC_TEXT"/>
This is the text that will appear on the screen.
Now you have to create a Content record that is associated to the DataResource. No matter what type of data resource you have chosen, the Content record is the same as:
<Content contentId="CN-01" contentTypeId="DOCUMENT" contentName="Content 01" dataResourceId="DS-01"/>
Note that the contentTypeId is “DOCUMENT”: all pages and sections of pages should be of this type.
Using the <content/> element in a screen definition
Now we can easily include the content directly inside the <widgets/> section of the screen definition with the following directive:
<label style="h1">OFBiz CMS Demo</label>
In the given example screen name is “main”.
Running the content driven screen
Make sure to have an entry in ofbiz-component.xml file for the data file created as:
<entity-resource type="data" reader-name="demo" loader="main" location="data/DemoCMSData.xml"/>
or if OFBiz is already up on your machine then you can also load data through webtools –> XML Data Import.
Request and View Mapping in Controller.xml
<security https="true" auth="false"/>
<response name="success" type="view" value="main"/>
<view-map name="main" type="screen" page="component://cmsdemo/widget/CmsDemoScreens.xml#main"/>
You are done with the basic setup of a static website using OFBiz CMS capabilities.
It was a very basic example. We’ll expand on the details and demonstrate more OFBiz CMS capabilities in upcoming posts. If you need help with OFBiz CMS in the mean time please feel free to contact HotWax Systems today!
Pranay Pandey has been in the software industry since 2006. He specializes in Enterprise Software Design and Development. At HotWax he currently leads the effort of architecting quality software products and training resources. He continues to be dedicated to the Apache OFBiz open source project since 2007 and became a committer in 2014. He leads our internal training programs in Apache OFBiz, ERP and new technologies under the roof of HotWax University. He is an Electronics graduate and has a masters degree in Computer Applications from Rajeev Gandhi Technical University, Bhopal (M.P.) India. He loves learning and sharing knowledge. He believes that one of the keys to success in this industry is to "keep learning". His hobbies are reading, writing, walking, running, cycling, cooking and watching science fiction movies.