Forum


Replies: 9   Views: 1073
Replacing variable inserts a footer on page 1 when not present in template
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 rwp401  · 26-05-2021 - 19:57

I have a template with footers on page 2 and thereafter.  None on page one.

When I replace variables in footer it inserts a footer on page 1.  This is a problem.

How do I fix this?

 

 

Posted by admin  · 26-05-2021 - 21:22

Hello,

What license and version of phpdocx are you using? Your username doesn't have any license tied.

About your question, phpdocx template methods don't change/add contents unless it's requested.

Please send to contact[at]phpdocx.com the username or email of the user that purchased the license you are using, and the most simple script (and template) that illustrates your issue so we can check it.

Regards.

Posted by rwp401  · 27-05-2021 - 18:37

Premium.  License will be given but not in open forum.

 

Posted by admin  · 27-05-2021 - 19:02

Hello,

We never request posting the license information in the forum.

As requested in our previous reply:

Please send to contact[at]phpdocx.com the username or email of the user that purchased the license you are using, and the most simple script (and template) that illustrates your issue so we can check it.

Regards.

Posted by admin  · 27-05-2021 - 19:17

Hello,

The code you have posted is not using any template method nor replacing any variable in the footer, it adds a header.
Adding headers do not remove/change footers, only existing headers are replaced. We have done some quick tests and everything is working correctly when adding headers/footers and also when replacing placeholders in them.

If you need to work with headers/footers per section, please check the documentation available on https://www.phpdocx.com/documentation/cookbook/headers-and-footers-for-sections.

For further support:

Please send to contact[at]phpdocx.com the username or email of the user that purchased the license you are using, and the most simple script (and template) that illustrates your issue so we can check it.

Regards.

Posted by rwp401  · 27-05-2021 - 20:14

I have now sent the entire code. Please not the subject of the email.  I have sent the template in prior email.

The sending email address of the email is how I was originally registered, but I cannot reset my password.

Original username was rwp40

 

Posted by admin  · 27-05-2021 - 21:35

Hello,

addHeader and addFooter removes existing headers and footers and add the new header/footer only to the last section of the document. These methods are available to be used when creating a DOCX from scratch, not with templates, because existing headers/footers are removed, and the new headers/footers are added only to the last section.

To add contents to headers/footers to a DOCX template you can use the following methods:

  • importHeadersAndFooters: the recommended way. You need to create a DOCX with the headers/footers to be imported and import them (default and first must be applied to addHeader)
  • add placeholders in headers and footers in the template and then use template methods to replace the placeholders by the new contents

Regards.

Posted by rwp401  · 28-05-2021 - 01:35

I would like to keep the footers from the template, but not add one to page 1 which the template does not have.  The template has footers from page 2 onward.  I do want to add headers starting on page 4+ but not change the footers in the process, which it seems to do.

Are headers and footers tied together so that adding one changes the other?

Posted by admin  · 28-05-2021 - 05:34

Dear Rick,

Headers and footers have some common tags, so changing one may affect others. As explained in our previous email, addHeader and addFooter methods aren't methods to be used with templates but with documents created from scratch.

Your template includes footers in the first DOCX, but they are hidden because the template uses <w:titlePg/> tag (tag shared by headers and footers) that hides the footer. The addHeader method removes it because this method is for documents created from scratch, not templates.

Please follow the approaches detailed in our previous email, there's no other way to change headers or footers in templates in the current release of phpdocx. The importHeadersAndFooters approachs work perfectly for your case.

Closed to avoid duplicated messages. The same is being sent by email.

Regards