Create a template and a simple script
Creating the Template Script
The script we will create is very simple and all it does is display the static text "Hello Magnolia World" on the Web page.
Let us create some folders and create the JSP.
- Create the following folders under your webapp folder:
templates/myProject/templates - Create a new JSP, for instance
helloworld.jsp, and add the following code:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head><title>Template Title</title></head> <body> Hello Magnolia World! </body> </html>
Where to put the script ?
It does not really matter where you put your JSP script, as long as it is within the webapp folder of your Magnolia instance. The path to the will be configured in the template definition.
In your instance you will find a /templates folder. That is usually where we put the template scripts. It's generally a good idea to structure your /templates folder, e.g. /templates/myProject/templates for template scripts and /templates/myProject/paragraphs for paragraph scripts, etc.
Create the template definition
Before we can use the simple template script, we have to create a "template definition". This is how Magnolia registers your template and knows how to use it. Once this is done, authors can use it with their pages.
The template definition is created in the configuration. Ideally, you should add it your own module, but for the sake of the exercise, we will add under the samples module, or the templating module.
Add a node under /modules/samples/templates and add the following properties, matching your own setup if necessary. You can group templates in subfolders, for organizational purposes, as shown here. (/modules/samples/templates/myProject/myTemplate)
Create a new page and test the template
Now that we have configured the template, we can go ahead and "use" the template. Simply create a new page in the website workspace, and assign it the new template. To view the page double-click on the icon.
This might come out as disapointing to some of you; this is a very basic page and does not actually show any reason to use Magnolia. But now that we have the basic infrastructure in place (the template script and the template definition), adding dynamic content on the page, linking it to dialogs, and other niceties should be a breeze, and will be explained in the next page !