OpenCms 8.5.1 got released last week and while test-driving the new edition I thought why not share a little knowledge about how to develop templates for OpenCms 8.x. The concept how it is done (and therefore the way to develop) changed rather significantly and this had been an impediment for days in our last project until we tackled it. This blog post aims to help you understand that new concept.
I want to give you two examples, one for version 7 and one for version 8. Both will have editable areas and the OpenCms 8 example will make use of so called “formatters” and inline editing, both being new state of the art features that were not available previously. These should make the life of content editors easier but developing got more complex, naturally.
I assume you are familiar with the general OpenCms terms, such as module, system-folder, site, template, workplace, structured content and you already know how to set up an initial instance of OpenCms.
For years I’ve been creating JSPs in a module’s template folder, and editors could create a new “Page with free text” and select the template.
That’s it. Sure, a template could include more elements and rely on multiple structured contents, but that is not a necessity. If you wanted to have a simple template with an editable area this code would have been enough for a start:
<%@ taglib prefix=“cms“ uri=“http://www.opencms.org/taglib/cms“ %>
Basic oldskewl OpenCms Template
Now let’s talk about OpenCms 8 template development. To understand why we need to create certain resources I’d like to start from an editor’s point of view: create a new page in a site.
In OpenCms 8 editors should work with the sitemap editor and simply drag and drop a new page into an existing site. For that to work we have to tell the Cms what model pages (~ the “new” templates) are available using the sitemap configuration located in /.content/.config of a site. Technically the drag and drop process copies an existing resource (the model page) to the destination (the index.html somewhere in the content).
Model pages are based on container page templates that reside in the module just like the old templates used to. Now, that’s one more step, why not link to the container page templates directly? Well, model pages *can* have pre-defined containers, the container page template is just the wireframe for containers.
Containers are elements that can be added to a page with the new drag and drop page editing of OpenCms 8. Containers are structured contents, so you need an XSD that defines the structured content and add module config that enlists all available resource types.
The XSD also defines a naming scheme where OpenCms should store the corresponding contents.
Finally the XSD defines a set of formatters. Depending on where you drag your content different representations can be chosen.
With this construct we accomplished the same as with OpenCms 7, but we can make use of OpenCms 8 features such as drag and drop, inline-editing and formatters.
From a developer’s point of view the new concept is far more demanding than previous ones. I hope the general reception will still be good, at least customers love the new features (my experience from the last project). Developing for OpenCms 8 is more difficult and more complex and not as intuitive as it used to be – developers will have to adjust to that, but your clients will be grateful for sure.
Attached you will find a module that contains both the simple template and the feature rich OpenCms8 container page (also with inline editing enabled) as well as content you can import in a test site. It should be easy to reverse engineer this little basic example, I hope it will help you get started developing templates for OpenCms 8. Happy coding! 🙂
The module: de.codecentric.opencms8.demo_1.1.zip
The content (please import into a new/blank site, otherwise this may overwrite existing sitemap configs): content.zip
codecentric summer event 2014
codecentric ist den Mitarbeitern bereits bekannt für seine rauschenden Feste, schon seit jeher feiern wir gerne und ausgiebig. Für 2014 wollten wir jedoch ein besonderes Event als Dankeschön an alle Mitarbeiter organisieren. Das Ergebnis war eine...
22.5.2014 | 3 Minuten Lesezeit
Monitoring JBoss AS start with JMX
As my colleague Robert described in his article “How to automate OpenCms module import ” we set up an automatic deployment process for one of our projects. However, we experienced some trouble with our way to check whether the app server finished starting...
7.9.2010 | 1 Minuten Lesezeit
JavaOne 2009: RIA development with JavaFX
A big “Hello” from JavaOne 2009 ! Me and three other colleagues are currently attending the number one Java conference in beautiful San Francisco along with hundreds of other top notch developers, architects and companies of the Java world (it’s been...
3.6.2009 | 2 Minuten Lesezeit
SVN Rule: Don’t commit on a tag – unless it is not a tag!
Imagine yourself committing your sources to your subversion repository after a hard day’s work and having this message pop up: Yikes! You are pretty sure you did modify the correct files and did not mess up your trunk/tag SVN meta files (again). Relax...
- Software development
2.3.2009 | 2 Minuten Lesezeit
Breaking News: codecentric team wins JBoss table soccer competition @Devoxx
Six happy codecentric employees are currently attending the Devoxx (formerly known as JavaPolis) conference in Antwerp, Belgium. Session topics such as Spring 3 (RESTful Spring MVC, Expression language), Java7 (dynamic languages, concurrency/parallelism...
11.12.2008 | 1 Minuten Lesezeit
Dein Job bei codecentric?
Agile Developer & Consultant (w/d/m)
An allen Standorten
Gemeinsam bessere Projekte umsetzen.
Wir helfen deinem Unternehmen.
Du stehst vor einer großen IT-Herausforderung? Wir sorgen für eine maßgeschneiderte Unterstützung. Informiere dich jetzt.
Hilf uns, noch besser zu werden.
Wir sind immer auf der Suche nach neuen Talenten. Auch für dich ist die passende Stelle dabei.
Head of Feelgood Management
Do you still have questions? Just send me a message.