TinyButStrong - the PHP Template Engine
Categories > OpenTBS with DOCX >

MergeBlock MySQL header/footer in docx

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs

By: mpol_ch
Date: 2016-12-29
Time: 13:25

MergeBlock MySQL header/footer in docx

I am having a docx template which is working perfectly.
Now I am trying to insert the result in area of header  and  footer with the following code, which is not working.
[a;block=begin] [h.firma]

When I put this code in outside in header area then it works perfectly.
Could you pelase give a hint how this code should be look like in header?

By: Skrol29
Date: 2016-12-30
Time: 00:21

Re: MergeBlock MySQL header/footer in docx

In DOCX, header and footer are saved in a separated sub-file.
This you have to use command OPENTBS_SELECT_HEADER or OPENTBS_SELECT_FOOTER before to manually merge in it.
  See http://www.tinybutstrong.com/opentbs.php?doc#opentbs_select_header

But automatic fields ([onload] and [onshow]) are always processed in header and footer.
By: mpol_ch
Date: 2016-12-30
Time: 18:38

Re: MergeBlock MySQL header/footer in docx

thanks for the answer.
But du you have an example how I can use this one? I appreciate much if you would give me some more information.

I used the following code but with no success:
[a;block=begin] [h.firma]   //For docx template in area header

In my PHP File:

$conn = mysqli_connect("localhost","****","","*****");

if (version_compare(PHP_VERSION,'5.1.0')>=0) {
    if (ini_get('date.timezone')=='') {

exit('Connect failed: '. mysqli_connect_error());

$TBS = new clsTinyButStrong;
$TBS->PlugIn(OPENTBS_SELECT_HEADER, [$Type[, $Offset])
$TBS->PlugIn(OPENTBS_SELECT_FOOTER, [$Type[, $Offset])

$Id=$_GET['Id']; //Rechnungs ID

$template = 'vorlagen/vorschuss.docx';
$TBS->LoadTemplate($template, OPENTBS_ALREADY_UTF8);

$TBS->MergeBlock('h',$conn,"SELECT *, f.f_name as firma FROM firma AS f INNER JOIN mitarbeiter AS m ON f.f_id = m.Firma Where m.MId=44"); //Reserviert für Header und Footer

$output_file_name = str_replace('.', '_'.date('d_m_Y').'.', $template);
$TBS->Show(OPENTBS_DOWNLOAD, $output_file_name);