When to Use RTF Subtemplates

RTF subtemplates can be used in various scenarios.

Following are several common use-cases for RTF subtemplates.

Reuse a Common Layout

Frequently multiple reports require the same header and footer content.

By using an RTF subtemplate to contain this content, any global changes are simplified and require updating only the subtemplate instead of each individual layout.

Conditionally Display a Layout Based on a Value in the Data

Subtemplates can also be used to apply conditional layouts based on a value in the report data.

By using the RTF template "choose" command, you can instruct Publisher to apply a different <?template?> defined in the subtemplate file.

You cannot conditionalize the import statement for the subtemplate file. Instead, you import one subtemplate file and conditionalize the call statement. You define the multiple <?template?> options in the single subtemplate file.


Assume you have a report that is sent to customers in India and the United States. You must apply a different address layout depending on the country code (COUNTRY_CODE) supplied in the data. This example uses the RTF templates if statement functionality to call the subtemplate with the appropriate address format.

The subtemplate file may look as follows:

<?end template?>

<?end template?>
To call the sub template with the appropriate address format:
  1. Create a Sub Template in the catalog in the following location:

    Customers/Invoice Reports

    Upload the RTF file and save the Sub Template as Addresses.

  2. In the main template enter the following to import the Sub Template:
    <?import:xdoxsl:///Customers/Invoice Reports/Addresses.xsb?>
  3. In the location where you want the address to display, enter the following:
         <?end if?>   
         <?end if?>    

When the report is run, the address format is properly applied, depending on the value of COUNTRY_CODE in the data.

Conditionally Display a Layout Based on a Parameter Value

This example illustrates how to display a different layout based on a user parameter value or a selection from a list of values. The parameter can be passed to the RTF template and used to call a different <?template?> within the subtemplate file based on the value.

You cannot conditionalize the import statement for the subtemplate file.


Assume in the report data model that you've defined a parameter named DeptName. Set up this parameter as type Menu and associate it to a list of values, enabling your user to make a selection from the list when he views the report in the Report Viewer (or when he schedules the report).

In the RTF main layout template, enter the following command to capture the value chosen by the user:


To display the layout based on this user selection, you can use an IF statement or a CHOOSE statement to evaluate the parameter value and call the associated subtemplate.

Use the CHOOSE statement when there're many conditional tests and a default action is expected for the rest of the values. For example, the Accounting, Sales, and Marketing departments each require a different layout. All other departments can use a default layout.

To display the layout:
  1. Create an RTF file and include the following template declarations:
       -  -  -  Specific Accounting Layout here  -  -  - 
    <?end template?>
       -  -  -  Specific Sales Layout here  -  - -
    <?end template?> 
       -  -  -  Specific Marketing Layout here - -
    <?end template?> 
       -  -  -  Default Layout here  -  - -
    <?end template?>
  2. Create a Sub Template in the catalog in the following location:

    Shared Folders/Executive/Department Expenses

    Upload the RTF file and save the Sub Template as DeptSubtemps.

  3. In the main RTF template, include the following commands:
<?import:xdoxsl:///Executive/Department Expenses/DeptSubtemps.xsb?loc=en-US?>


   <?end when?>
   <?end when?>
   <?end when?>
   <?end otherwise?>
<?end choose:?>

When the user runs the report, the layout applied is determined based on the value of DeptName. For more information on CHOOSE statements in RTF templates, see Insert Choose Statements.

Handle Simple Calculations or Repeating Formulae

Simple calculations can also be handled using an RTF subtemplate. More complex formulae should be handled with an XSL subtemplate.


This example illustrates setting up a subtemplate to contain a formula to calculate interest.

The subtemplate performs the interest calculation on the data in this report and passes the result back to the main template. The sub template accommodates the possibility that multiple reports that call this functionality might have different tag names for the components of the formula.

Assume that you've the following XML data:

To set up a sub template to contain a formula for calculating interest:
  1. In an RTF file, create a template declaration called calcInterest. In this sub template define a parameter for each of the elements (principal, interest rate, and years) in the formula. Note that you must set the default value for each parameter.
       <?number($principal) * number($intRate) * number($years)?>
    <?end template?>
  2. Create a Sub Template in the catalog in the following location:

    Shared Folders/Subtemplates

    Upload the RTF file and save the Sub Template as calculations.

  3. In the main template, enter the following to import the sub template:
  4. In the location where you want the results of the calculation to display, enter the following in a Publisher field:
    <?end call?>      

    Note the use of the @inlines command here. This is optional. The @inlines command forces the results to be rendered inline at the location in the template where the call to the sub template is made. Use this feature, for example, if you want to keep the results on the same line as a string of text that precedes the call.