Tutorial 2 - Module Libraries

This tutorial shows how to create and use module libraries. Module libraries are files that contain only module definitions and can be included from other ModPro files. The benefits of using ModPro really becomes apparent once you start to use module libraries. Modules that are common to more than one page can be extracted to a module library and used from anywhere. In this tutorial we will learn how to create a module library and include it.

The entire examples can be viewed below. See tutorial/tutorial2/tutorial2.xml and tutorial/tutorial2/common.xml

For this tutorial we just took the two modules that were defined in Tutorial 1 and moved them into a new file called common.xml. The file common.xml is now a module library. Just like any ModPro file the root element is <mpml>. The difference is that a module library doesn't contain a <html> element. It only contains <module> elements.

<?xml version="1.0" encoding="ISO-8859-1" ?>
<mp:mpml xmlns:mp="http://www.worldtreesoftware.com/mpml">

  <mp:module name="headerContent">
    <title>Tutorial 2</title>
  </mp:module>
        
  <mp:module name="bodyContent">
    <h1>Welcome to ModPro!</h1>
  </mp:module>

</mp:mpml>
      

To use this module library in tutorial1.xml we need to add an <include> element.

<mp:include href="common.xml"/>
      

Now we can reference the modules just as we did before.

<mp:module ref="headerContent"/>
<mp:module ref="bodyContent"/>
      

Here is what tutorial2.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>
    <head>
      <mp:module ref="headerContent"/>
    </head>
    <body>
      <mp:module ref="bodyContent"/>
    </body>
  </html>

</mp:mpml>
      

After compiling you should see tutorial2.html created and it should look very similar to tutorial1.html.

<Previous Tutorial | Next Tutorial>