Velocity Model and Data Objects in Apache Roller

by | December 2009 | Beginner's Guides Content Management Java Open Source

In this article by Alfonso V. Romero, we'll see some of the Velocity elements used in Roller to display data from your weblog and work with Roller's model and data objects to access your weblog's data from custom templates.

To know more about $model object and $url read Working with Templates in Apache Roller 4.0.

Velocity model and data objects in Apache Roller

There are several standard model and data objects you can use in Apache Roller to access your weblog's data. Some of the most widely used are $config, $model, $url, $utils, $weblog, $weblogCategory, and $weblogPage. In the following exercise, you'll get to work with the $config object.

The $config object

This model is used to access Roller's site-wide configuration parameters, such as the e-mail address of Roller's administrator, the name of the Roller site, and so on.

Time for action – properties of the $config model object

The following exercise will show you how to use some properties of the $config model object inside your custom template:

  1. Go to your custom template editing page, and replace the six lines of code below the <body><html> line with the following lines:
    Welcome to my blog, <b>$model.weblog.name</b> --> <i>$config.
    siteDescription</i> </br>
    I'm using Apache Roller Version <b>$config.rollerVersion</b> </br>
    You can e-mail me at <b>$config.siteEmail</b> if you run into any
    problems in this site. </br>
    This is my first template </br>
    My weblog's absolute URL is: <b>$url.absoluteSite</b> </br>
    </br>
  2. The entire code of your template should look like the following screenshot (the code you have to change is highlighted):

    Apache Roller 4.0 – Beginner's Guide

  3. Save your changes and click on your template's [launch] link to open a new tab in your web browser and see the results:

    Apache Roller 4.0 – Beginner's Guide

  4. Close the results tab if you like, but leave the Frontpage: Templates window open for the next exercise.

What just happened?

The following table summarizes the $config object properties you learned to use in the previous exercise, along with their value:

Property

Definition

Value

$config.siteDescription

Shows your site's description.

My First Installation of Apache Roller

$config.rollerVersion

Shows the Apache Roller version used.

4.0.1

$config.siteEmail

Shows the site administrator's email.

alromeromx@gmail.com

You can find all $config parameters under Roller's Server Admin tab:

The $model, $category, and $entry objects

These objects are used to access all the data for a specific weblog: weblog entries, categories, comments, among others.

Sign up for a Packt account to see the rest of this article

Now that you've read a few articles, you might want to consider signing up for a Packt account. It takes a matter of seconds, will give you access to all the articles on PacktPub.com, and once you've signed up you'll be returned here to carry on reading your article.

Furthermore, you'll gain access to nine free ebooks, and be offered a free trial of PacktLib, Packt's online library. Simply enter your details here, or log in to your existing account.

Log in

...or register

Post new comment

Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Sort A-Z