Categories > OpenTBS with DOCX >

MergeField in header

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Tobias
Date: 2014-04-10
Time: 03:49

MergeField in header

I currently try to change a header with MergeField in a document.
I am not able to change or create new global variables as I run the code in a Drupal 7 code field with limited functionality for global variables
(at least I can not figure out how to change them at runtime without a lot of cache clearing and stuff like that).

Markers [angebot.nummer] are only replaced in the content and not in the header if I use:
$mypath= libraries_get_path('TBS').'/template_angebot.docx';
$TBS->LoadTemplate($mypath,OPENTBS_ALREADY_UTF8);

$aArray = array(
   'titel'=>$atitel,
   'nummer'=>$anr);
$TBS->MergeField('angebot',$aArray);

$TBS->LoadTemplate('#word/header1.xml');
$TBS->MergeField('angebot',$aArray);

$TBS->Show(OPENTBS_FILE,'public://'.'temp.doc');

The standard merging processes within my docx content.xml works well, but the merging of fields in the header requires to change the header1.xml file.
I tried to adapt some of the code in http://www.tinybutstrong.com/forum.php?thr=3190 but I was not able to perform a Field merge on the content (To be clear: I want to merge fields in header and content from one template .docx file).

It would be great if someone could provide me a minimum working example how to merge fields/blocks in a header without onload/onshow while also changing the templates main content.

Thanks in advance!
By: Skrol29
Date: 2014-04-10
Time: 13:54

Re: MergeField in header

Hi,

> I am not able to change or create new global variables as I run the code in a Drupal 7 code field with limited functionality for global variables

You can switch automatic fields to your custom array using method ->SetVarRef().
http://www.tinybutstrong.com/manual.php#php_varref

> I want to merge fields in header and content from one template .docx file

I'm surprised that your code did not work. It should be.
May be your TBS tags are no in "header1.xml" but in "header2.xml" or "header3.xml".

There is a stable beta version that should be released very soon (as soon as the documentation is updated) and which helps to select headers and footers.
Do you want to try ?
By: Tobias
Date: 2014-04-12
Time: 00:14

Re: MergeField in header

Hello Skrol,
Thanks for the quick reply and your great work on this plugin !

I made a trivial coding error, which I did not copied into the example. Merging headers works now.
Thanks for pointing me to the ->SetVarRef(), this makes some tasks much easier !

I am open to test your new version. Just contact me at the email address I entered with this post.
By: Skrol29
Date: 2014-04-12
Time: 23:16

Re: MergeField in header

Hi,

The new version is just released yesterday.
OpenTBS version 1.9.0