Showing posts with label Sub Templates. Show all posts
Showing posts with label Sub Templates. Show all posts

Monday, 28 April 2014

Page Structure in RTF templates Headers Footers and Continued on next page

One issue that has come up recently  was adding some structure to our BI Publisher  templates .  adding headers and footers to them  and  the ability to display different headers and footer depending of  we are on the first middle or last pages of a report .  that initially caused quite a bit of head scratching until I discovered a couple of trick that solved all my problems

firstly stay away from the header and footer sections in word  I had a go with these initially but there not reliable if they work at all.  the solution turned out to be just a couple of XML tags

<?call-Template: PageHeadder?>
     <?start:body?>
               Do report Body Stuff in  here    
    <?end body?>
<?call-Template: PageFooter?>

where PageHeadder and PageFooter were a couple of sub templates I had created earlier .  works lovely every time 

Now what do you do if you want a different header for the first and last pages  or if you want the middle pages to print Continued at the bottom ?

well it turns out that this is quite a common question asked on the interwebz and seems to have a nice elegant solution  the excellent chaps over at the never name it blog have put this together Never Name it Blog Page Structure

and because it seems to be a question asked a lot  they put this excellent guide together too for those anoying times where you want reports to print continued on next page on every page apart from the last one Last Page Continues


Monday, 31 March 2014

BI Publisher Sub templates and calling them conditionally

I had a few issues today that sent me off on an oddesy to learn about sub templates and how to use them . and now I've had a fiddle with them they have totally revised my approach to writing templates.  there really dead useful :).

 I'm working on one of our company invoices and  was having quite an unpleasant time trying to work out how the hell to make this template work . like every one else out there I should imagine our invoices can have  lots of different ways to display a line item and you can have any number of line items on a page how on earth was I going to cope with invoices that went over to more than one page ?????   this is the type of thing that on more than one ocasion has reduced me and Mike to sobbing wrecks and reaching for the poultry with one hand and the Whisky with the other when we tried to do this with transform

dead easy it turns out.

This where sub templates come in .  Sub templates are small templates in there own right that you can either store in another RTF document  or stick at the bottom of your template out of the way (which is what i did  in this case) 

My first issue was to make sure the header and footer on each page were there and displayed properly . I  had one header section which is displayed on every page  and 2 footers. one which is displayed on the last page  and one  on all the others . so I created these  as sub templates.  to do that i just wrapped them in <?Template:?> tags  like this 













then i just popped <?call-Template: PageHeadder?> in the  header of my word RTF Template. 

Next I tackled the footer issue by doing exactly the same I created 2 Templates  a page footer one and an last page footer one  then used a choose statement to choose which one to display in the footer  using a bit of code like this 

<?choose:?>
          <?when:PrintTax_ID5=“Y“?><?call:PageFooterWithTax?><?end when?>
           <?otherwise:?><?call:PageFooterNoTax?><?end otherwise?>
<?end choose?>


finally I created a sub template for each of the different line types i had  and used exactly the same technique to call the sub template for the line type i wanted to display .  yet again  no swearing sobbing or poultry bothering required