Tutorial - Use Templates & Modules and Bind variable styles


In this tutorial, we will learn to:

  • Create a template in a Module and apply it in a Generator
  • Map variable styles of a Modules with the styles of a Generator


We will start from the project developed in the first 15 minutes tutorial. If you did not run the first tutorial, you can import the final project in Eclipse: select File -> New -> Example and then pxDoc Final Library Example.

From this project, we will:

  • Create a Module with a template specifying the author presentation (name, biography and photo)
  • Apply this template in the existing Generator


Create a Module to host the template

First, create a Module: in Eclipse, select File → New → Project → pxDoc project:

  1. Call the project mymodule
  2. Select "Module" as kind of project and call the class ModuleLibrary.
    Select Variable Styles to be able to define the content regardless to the stylesheet that will be finally used
  3. Once the project is created, add our Library metamodel as dependency of the project



Let's go back to ModuleLibrary.pxdoc and define Title as single variable style for this module:


 Create the template 

 We declare a template called authorBiography that will be used to generate the author presentation (biography + picture)

template authorBiography(Author author) {

 Press [CTRL]-[SHIFT]-O to get Eclipse automatically add the relevant import



Now, cut the code we wrote to define the author presentation and paste it in the template.

Replace the Heading1 style from the generator's stylesheet by Title variable style: 

template authorBiography(Author author) {
	#Title {
		image path:author.
			picture height:2.8cm hPosition(align: right relativeFrom:margin) vPosition(align:center relativeFrom:line)
	font bold underline color: "122,91,255" {"Biography" }
	section columns:2 type:continuous // Starting a continuous section with 2 columns
	italic {author.biography }
	section type:continuous // Get back to a single column


We are now ready to use this template in generators.


Declare the module and apply the template in our existing generator

We first need to add our module as dependency of our generator. Open the MANIFEST.MF and add mymodule to the Required Plug-ins:


In our generator LibraryGenerator.pxdoc, just add with:ModuleLibrary to the declaration of the generator (line 8 below). You can use [CTRL]-[SPACE] to get suggestions from Eclipse


Eclipse tells us that we need to bind the style Title from the Module with a style from the generator's stylesheet. 


This is done with the styleBinding property. Here again, we let Eclipse suggest us things. 

  • Suggestion of the module styles we need to map (Title->):


  • Suggestion of the styles from the stylesheet (Heading1):



If not already done, delete the previous code describing the author presentation, and replace it by the following code to apply the template:

	apply authorBiography(author) 




 You can launch the generation of the document to check that we have exactly the same result as previously.


Launch the generation

 Launch the project as an Eclipse application, in Run or Debug mode.

If you did not run the first 15 minutes tutorial, you need to import the Library model in the second Eclipse that opens: select File -> New -> Example and then pxDoc Library Test Model


Launch the generation in the second Eclipse by right-clicking on Library MyLibrary → pxDoc → 15 minutes tutorial.