Integrating Grails With Weceem 2 : Creating custom content

26 / Jun / 2012 by Manoj Mohan 0 comments


Last time we met, we  were talking about how to get started on Integrating Grails With Weceem CMS.

Moving on, when you actually use it in a typical product development scenario, you will more often that end up customizing the content being served by Weceem. So this blog will concentrate on exactly that….. Creating Custom Content.

For this blog, I’ll be taking the scenario wherein the CMS will be able to render Employee specific content like name, age, gender and designation along with the traditionally served content. For doing this,  we will be creating a structure where all the “employee” content/objects would be grouped, such as an Employee Group that could be  constitute a team or the entire organization itself.
Eg: A and B employees under Sales and C and D under Marketing or A,B,C,D all under say ACME corporation itself.

Getting Started …

Assuming that you have already gone through the previous blog and/or have setup Weceem onto your system, simply type

[shell]grails create-content-class com.weceemDemo.Employee[/shell]

This creates a temporary placeholder like domain onto which we can insert fields as per our needs. So taking the Employee class in mind, add things like ..

String name
String age
String gender
String designation

static constraints = {
name(nullable: false)
age(nullable: false)
gender(inList: ["Male", "Female"], nullable: false)
designation(inList: ["Manager", "Employee"], nullable: false)

static editors = {
name(editor: ‘String’)
age(editor: ‘Integer’)
gender(editor: ‘SelectInList’)
designation(editor: ‘SelectInList’)


Running your application now and logging in, you can see that when you hit the ‘New Content’ link on your CMS page you would see an entry for the Custom Content that you have just created.

The name of the class looks kinda ugly right now. You can correct that by adding a label in your i18n message bundles.


Next comes the part where we create the Team/Organization domain that’ll be used to group these employees. It will have a description field that will provide some info about the group and will reference a template that will be used to render employee content.

To do this, type in ..

[shell]grails create-content com.weceemDemo.EmployeeGroup[/shell]

In EmployeeGroup add something like …

WcmTemplate template // This will hold the template used to render employee data
String content

static constraints = {
template(nullable: true)
content(nullable: false, maxSize: WcmContent.MAX_CONTENT_SIZE)

static mapping = {
template cascade: ‘all’, lazy: false // we never want proxies for this

static editors = {
content(editor: ‘HTMLContent’) // Forces use of the HTMLContent rich editor
template(group: ‘extra’)

Moving Onto Some CMS code …

Now we move onto creating a template that will be used to render the employee content. We will create this template in the CMS itself.
So in the CMS landing page select the Templates folder. Now click New Content, select Template and add the following …

<wcm:eachChild var="c"> <!– Iterating TagLib provided by Weceem . This will iterate over the content inside the associated folder. –>
<li><b>Name</b> : ${}</li>
<li><b>Age </b> : ${c.age}</li>
<li><b>Gender</b> : ${c.gender}</li>
<li><b>Designation </b>: ${c.designation}</li>

As you might have noticed, an advantage of using Weceem is that your GSP syntax is supported.

Now that you have the structure in place, all you need to do is add some content.

Finally … Lets test it out

So first go to the CMS landing page and create a EmployeeGroup

On this page, go to Extras -> Template. Select the template you have created here and hit update.An alias URI will be created from the title itself but it’s better to provide a unique ‘n’ recognizable alias URI like ‘acme’.

Next add Employees inside the EmployeeGroup that you have created. Make sure that everything you have created has the status ‘Published’ for it to be visible.

That’s all. Simply hit the URI you had provided or hit the “preview” button on the EmployeeGroup Edit page and
VOILA …… you will see a list of Employees of Acme Corp being rendered through the CMS.

So now every time you need to add an Employee all you need to do is create an Employee content and publish it. It would be immediately visible on your application webpage.

Manoj Mohan

Leave a Reply

Your email address will not be published. Required fields are marked *