Tutorial 3 - Modules as Templates
In this tutorial we take the example from the previous tutorial and turn it inside out to create a page template.
This allows us to create a page layout that can be used by all pages in our web site.
Content for individual pages is defined in each page's source file without having to duplicate page layout.
The entire examples can be viewed below.
See tutorial/tutorial3/tutorial3.xml
and tutorial/tutorial3/common.xml
For this tutorial we will modify the files from tutorial 2 to create a page layout template.
First we take all of the HTML from inside the <html> element and move it to a module in common.xml called "pageTemplate".
<?xml version="1.0" encoding="ISO-8859-1" ?>
<mp:mpml xmlns:mp="http://www.worldtreesoftware.com/mpml">
<module name="pageTemplate">
<head>
<mp:module ref="headerContent"/>
</head>
<body>
<mp:module ref="bodyContent"/>
</body>
</module>
</mp:mpml>
Then we take all of the modules that were previously defined in common.xml and move them back into tutorial3.xml.
Now the page layout template has been centralized and the page content is defined in the page's source file.
At this point we could create any number of pages, all using the same template, but with different content.
Here is what tutorial3.xml now looks like.
<?xml version="1.0" encoding="ISO-8859-1" ?>
<mp:mpml xmlns:mp="http://www.worldtreesoftware.com/mpml">
<mp:include href="common.xml"/>
<html>
<mp:module ref="pageTemplate"/>
</html>
<mp:module name="headerContent">
<title>Tutorial 3</title>
</mp:module>
<mp:module name="bodyContent">
<h1>Welcome to ModPro!</h1>
</mp:module>
</mp:mpml>
After compiling you should see tutorial3.html created and it should look very similar to tutorial2.html.
<Previous Tutorial | Next Tutorial>
|