|
|
Want to know more about Packt's Article Network? Interested in contributing your article ideas? Please visit our FAQ for more information. See More BROWSE
All Titles WordPress Web Services SOA BPEL Web Graphics & Video Web Development RAW Portugues, Espanol, Italiano, French PHP/MySQL Oracle Open Source Networking & Telephony Moodle Microsoft & .NET Linux Servers jQuery Joomla! JBoss Java e-Learning e-Commerce Dynamics Drupal CRM Cookbook Content Management Beginner Guides Architecture and Analysis AJAX Future Titles Recently Published Titles 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. See More In this article by Alfonso V. Romero, you'll learn to build a theme from the ground up, using several templates properties, and methods commonly used in Roller themes. To learn more about some of the properties and templates used in Roller themes read Working with Templates in Apache Roller 4.0. |
Working with Templates in Apache Roller 4.0
Your first templateIn essence, a theme is a set of templates, and a template is composed of HTML and Velocity code. You can make your own templates to access your weblog's data and show this to your visitors in any way you want. Creating and editing templatesIn Apache Roller, you can create, edit, or delete templates via the Frontpage: Templates page. Let's see how to use this wonderful tool to create and edit your own templates! Time for action – creating your first templateIn this exercise, you'll learn to create and edit your first custom template via Roller's admin interface:
What just happened?Now you know how to create your own templates! Although the previous example is very simple, you can use it as a starting point to create very complex templates. As I said before, templates are composed of HTML and Velocity code. The template we wrote in the previous exercise uses a few basic HTML elements, or tags:
Also, there are some elements from the Velocity Template Language, along with an example from the previous exercise:
These are just some of the basic HTML tags and Velocity elements you'll learn to use for your templates. In the following sections, we'll see some more, along with elements from the Velocity Template Language. The Velocity template languageAll templates in Roller use HTML tags, along with Velocity code. In the next subsections, you'll learn about some of the most widely used Velocity elements in your Roller templates. Using Velocity macros in your Roller weblogA macro in Velocity is a set of instructions that generate HTML code based on data from your weblog. They are very helpful when you need to do the same task more than once. In the following exercise, you'll learn to use some macros included in Roller in order to show your weblog data to your visitors. Time for action – showing your weblog's blogroll and most recent entriesNow you will use the Velocity Template Language to show your weblog's bookmarks (blogroll) in your custom template, along with the most recent entries:
Apache Roller 4.0 – Beginner's Guide
What just happened?In Velocity, a macro starts with the # character. In the previous exercise, you used two Velocity macros: one to show your weblog's blogroll and the other to show your weblog's most recent entries. There are two Velocity statements implicated in the blogroll macro: #set($rootFolder = $model.weblog.getBookmarkFolder("/"))The first line gets the root bookmark folder (represented by "/") and assigns it to the $rootFolder variable. The second line is the showBookmarkLinksList macro, which uses the value in $rootFolder to generate a bookmarks list and show it in your template:
The two false arguments after $rootFolder indicate that we are not using subcategories inside the bookmark links list. If you want more information about these arguments, check the Roller template guide included in the Roller installation. There are two more lines involved in the recent entries macro: #set($entries = $model.weblog.getRecentWeblogEntries("nil", 5)The first line gets the 5 most recent entries from your weblog and assigns the result to $entries. The "nil" parameter specifies that Roller must get the five most recent entries from all categories. If you want to get the most recent entries from a specific category, just replace "nil" with the name of that category. The next line is the showWeblogEntryLinksList macro, which uses all the entries included in $entries to generate a list with links:
SummaryIn this article, you learned how to create and edit your first template in Roller. Specifically, we covered:
Apache Roller 4.0 – Beginner's Guide
About the AuthorAlfonso Romero is a freelance computer consultant and translator from Mexico. He's been working with Linux and open source software since 1999. He started operating his first web server (Apache) from a PC at home, offering free hosting services to experiment with Postfix, Squirrel Mail, MySQL, Apache, Tomcat, and Virtual Hosting. Since then, he's been working as a computer consultant for several clients in Mexico – writing Java, C++, and Web applications. Since 2000, he has worked for Pearson Education in Mexico as a computer books freelance translator and consultant. His latest book translations are the Spanish versions of Java How to Program, Seventh Edition, from Deitel & Deitel, and C++ How to Program, Sixth Edition, also from Deitel & Deitel. Al enjoys writing tutorials and teaching about Java, C++, PHP, the Apache Web server, Tomcat, MySQL, Web applications like Apache Roller, and all of the wonderful open source applications used today, and when he's not experimenting with new trends in Open Source applications, he enjoys playing his electric guitar. Books from Packt
|
| ||||||||