This section explains the examples of usage of the main and child templates. These examples allow you to create documents as the main template and reuse the content of child templates into it.

Preparatory Step

Define a child template that you will use as in Examples 1, 2, and 3. This child template contains the header line and named sections (Section A and Section B). Type the following lines in the document that you want to define the child template:

This is the child template.
#sectionBegin(Section A)
This is Section A.
#sectionEnd
#sectionBegin(Section B)
This is Section B.
#sectionEnd

Usage in Example 1

This example shows how to statically include the complete child template as shown in the Preparatory Step. To include it, call the $import.include('child.docx') method. Note that there is no specified path. This path to the child template shows you that the main and child templates reside in the same directory. Type the following lines in the document that you want to include all of its content to the report:

#import ('import', 'com.nomagic.reportwizard.tools.ImportTool')
This is the 1st main template
Include child template
$import.include('child.docx')

The output right below will include the entire text from the main template (right above) and from the child template minus the template directives. The included content will be then parsed and stripped of all velocity directives. The output is as follows:

This is the 1st main template
Include child template
This is the child template.
This is Section A.
This is Section B.

Usage in Example 2

This example shows how to statically include a section of the child template as shown in the Preparatory Step. To include the section named Section A from the child template, call the $import.includeSection('templates/child.rtf', 'Section A') method. In this example, the main and child templates reside in different directories, which means that the child template will reside in a subdirectory called templates. This templates directory will thus reside in the same directory as the main template. Type the following lines in the document that you want to include its content in Section A to the report:

#import ('import', 'com.nomagic.reportwizard.tools.ImportTool')
This is the 2nd main template
Include Section A
$import.includeSection('templates/child.rtf', 'Section A')

The output will be:

This is the 2nd  main template
Include Section A
This is Section A.

Usage in Example 3

This example shows how to dynamically include the section of a child template as shown in the Preparatory Step. Before dynamically including the section of the child template named Section B, set a variable for the file location of the child template [#set ($child = "C:/ImportTool/child.rtf")] and another one for the section name to be included [#set ($section = "Section B")]. To include the Section B section from the child template, call the $import.includeSection($child, $section) method. In this example, the child's template location is provided by an absolute path. Note that dynamic values must not be specified in a pair of quote marks, otherwise the section will not be included. Type the following lines in the document that you want to include its content in Section B to the report:

#import ('import', 'com.nomagic.reportwizard.tools.ImportTool')
This is the 3rd main template
Include Section B
#set ($child = "C:/ImportTool/child.rtf")
#set ($section = "Section B")
$import.includeSection($child, $section)

The output will be:

This is the 3rd main template
Include Section B
This is Section B.

The Import tool supports DOCX, RTF, HTML, XML, and text files only.

Usage in Example 4

This example shows how to include a document as an Attached File element in a project. First, you need to create an Attached File element in a project. The File property will then be used as a parameter to make a reference to the Attached File element. Type the following lines in the document that you want to include the content of the Attached File element to the report:

#import ('import', 'com.nomagic.reportwizard.tools.ImportTool')
#foreach($included in $AttachedFile)
	#if($included.file == "included.docx")
		$import.include($included)
	#end
#end

Including a document as an Attached File element in a project.