When you develop a report you usually want to have a header and footer section. And when you develop more reports you probably copy and paste the header and footer section from the first report so that all the reports will have a same look and feel with a company logo, report title, reporting date, copy right, etc.
Now you have developed a lot of reports with the same header and footer and you need to change the report title font size or need to change the company logo in the header section, what would you do? Imagine if you have 100 reports already developed! Obviously you don’t want to visit every single report and make such changes in each of the RTF templates.
In order to avoid from visiting each of those hundreds of the reports you wish having just one common header and footer template, in which you can design the header and footer and you can import from all the reports you have. When you need to make such changes for the header and footer only you need to do is to visit only this common header and footer template and make the change. How easy!
This is a very common requirement for any reports development with BI Publisher and BI Publisher addresses this type of requirement with its Sub-Template feature. But somehow it can often be slipped out from the reports design until you hit this maintenance concern mentioned above. I guess that’s because our main focus is how to bring the data into the report and design the layout and formatting for the data when we start the development and we just want to get our report done without taking an account of the long term maintenance perspective.
Also this is not really well documented as a practical and best practice way. There are many information about this common template (called Sub Template in BI Publisher) out there but it’s not really clear as a complete picture of how to implement it and deploy to a real environment.
So here comes the post I’m writing today. I’m writing this using an example of the header and footer, but as you can imagine it doesn’t have to be only for the header and footer. Anything you want to have in a central place and apply to all the reports you can apply this information.
Sub-Template as Common Template
With BI Publisher you can use a Sub-Template feature to create the common template where you can design common objects such as the header and footer. The Sub-Template can be a RTF template or XSL style sheet, which can contain common formatting and layout information, and can be imported from any reports. So for example if you want to have a same header layout then you can design the header in the Sub-Template file and import the header, which you just designed in the Sub-Template, from all of your RTF template files. When you get a new requirement or modification request for the header then you can only modify this one header in the Sub-Template file and no extra work needed.
Here is a list of the steps how you can implement the common Header and Footer Sub-Template.
- Create a Sub-Template for the Header and Footer
- Locate the Sub-Template at a Web Server or file system that BI Publisher server can access to
- Call the Sub-Template from the main templates
- Call the header or footer section
You can create a new RTF template and use a ‘template’ syntax to design the header or footer layout and formatting.
There is a starting syntax (<?template….?> and ending sytax (<?end template?>), so you need to design the header or footer layout first then surround it with the starting template and the ending template syntax.
Header contents should be here…
Once you created the sub-template now you can reference it from the main RTF template files. It can be referenced by either File or HTTP option. The File option is to locate the sub-template file on the file system, which means the sub-template needs to be on the same machine where the main template files are. The HTTP option is for the sub-template to be accessed through HTTP so the sub-template needs to be on a web server and it should be accessible from other machines with HTTP.
First, you need to import the sub-template in the main RTF template. You can import either with File or HTTP option. This import statement needs to be set at the very beginning of the file.
Here is the example:
Example with File reference:
Example with HTTP reference:
Once you imported, now you can use ‘call-template’ syntax to call and embed the header or footer layout and formatting at the header or footer section in the main template.
And, that’s it! Now you have a common header and footer template and can apply it to any report you have. Very simple.
I will discuss tomorrow about some best practice on how to deploy and tips. So stay tuned!