Replies: 5   Views: 3036
Addtemplatevarialble for headers
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by RamirezZ  · 22-06-2011 - 19:30

I use the function addTemplateVarialble quite a lot. Mostly it works great and really helps in my developing process. There is one issue which i can not find a good workaround though: If I try to add variable to headers it rarely works. It's quite random, for some headers i can add a Template variable but for most the tag wont be replaced. I tried with templates created with word2007 and word2010. I also tried out different templateSymbols.
Is this a known issue? Has anyone the same problem? Has anyone found a good workaround?
find help tBy the way, is it on purpose that old forum topics cant be read anymore? Maybe i wouldhere...

Posted by RamirezZ  · 11-04-2013 - 12:13

oke, I figured out why the template variables often not work with templates made with word2007 or 2010: for some reason, word often creats 3 header and footer files in stead of one. So we have in the word folder of the docx file three files for the header (header1.xml, header2.xml, header3.xml). And three for the footer. The problem is, that phpdocx only reads the first, called header1.xml.

There are two possible workarounds: The first one is, to simply copy the content of header2.xml and header3.xml to header1.xml in the template. I did not test this out, but it should work.

The other workaround (and I think this is the better): Rewrite the CreateDocx class and the CreateTemplate class, so that it reads all the header files instead of just header1.xml. The idea is to change the variable $_header from a string to an array storring strings and make the changes in the code accordingly. Its really not much you have to change. If anyone is interested in further details, I can post the changes I made. Of course only if the admins do not mind.

Posted by MVa  · 11-04-2013 - 12:13


The question and answer doesn't appears in the forum

Can you explain how we can add header template variable ?


After my post it reappears, i'm interested for your workaround solution

thx in advance

Posted by RamirezZ  · 11-04-2013 - 12:13

I know it's quite strange that older posts seem to disappear. I hope this is fixed soon.

As said, the idea is to change the variable $_header and $_footer from a string to an array storring strings and make the changes in the code accordingly. You would have to change several lines of code in the source. If you send me a message on ill send you the two files i changed. Of course only if the admins do not mind. But I guess they do not since they did not react on my first post.
hope that helps.

Posted by admin  · 11-04-2013 - 12:13


The next version of phpdocx pro will solve an issue that fail when there’re more than one header (or footer) created by Word.