Forum


Replies: 4   Views: 2501
Template - replacetablevariable() with html link
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 mcgarryit  · 11-10-2017 - 17:29

Hi

I have several tables in my template.

The replaceTableVariable() function works fine, replacing the repeating rows of data in each table.

However, one of the table cell values is meant to be a proper HTML link. At the moment, I am just inserting the text of the URL. I would like to be able to add a proper functioning link. (I also produce a PDF format of the document, and would like the link to function properly in the PDF.)

I see the addLink() and replaceVariablebyHTML() methods, but cannot see how to apply these in the context of a table row being replaced using replaceTableVariable().

Is there any simple way for me to format the value for the link variable, in my assoc array, before I pass it to the method replaceTableVariable()...?

Thanks

Paul

Posted by admin  · 11-10-2017 - 17:54

Hello,

Yes, you can accomplish what you need using WordFragments. Instead of strings, you can add WordFragments as values to fill tables (you can also use WordFragments for almost any method).

We recommend you to read the information available about WordFragments on:

https://www.phpdocx.com/documentation/practical/wordfragments-and-wordml

And also check the included samples in the examples/Template/replaceTableVariable folder; sample_3.php fills a table using WordFragment with links and images (and you can use almost any other contents such as HTML, charts, texts, paragraphs... as WordFragments).

Regards.

Posted by mcgarryit  · 12-10-2017 - 11:28

Thanks.

Have found that works very well.

However, has created a new problem.

I am including the WordFragment.inc class, where I need to create these links. And the code is working. But for some reason, the obfuscated code is being output to the browser, as if it has not been recognises as php code.

Any suggestions?

Regards

Paul

Posted by admin  · 12-10-2017 - 11:41

Hello,

The obfuscated code is only of the trial package, purchased packages don't include any obfuscated file. Maybe you are using the trial package instead of a purchased license? after you buy a license you need to download a new package to remove trial watermarks and get access to the code of files.

The autoloader of phpdocx includes all files of the library doing a require of the CreateDocx.inc file, so you don't need to add the WordFragment.inc manually. Please check the included samples, all of them include just CreateDocx.inc to use all methods available (except MultiMerge, DocxUtilities, Crypto, DigitalSignature and the transform method that can be used standalone).

Regards.

Posted by mcgarryit  · 12-10-2017 - 11:55

Thanks.

Leaving out the include or require statement worked.

For clarity, I have to use the TRIAL version on development server, as it is a different domain.

Also, working with very old codebase, so not using composer, autoloaders etc. Surprised it works.

I have set the include path to refer to the directory where I have loaded the phpdocx code.

But all working now :)

Regards

Paul