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 

No comments:

Post a Comment