Forum


Replies: 4   Views: 3135
Html 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 champton  · 24-06-2011 - 17:35

I want to add HTML to a variable in my template.docx file. The HTML is being passed from a textarea as a post and when it comes through in my docx file it is HTML not formatted for word

$docx->addTemplateVariable('event_details', $details, 'html');

but it works when I enter the actual HTML in the function and not pass it as a string.

$docx->addTemplateVariable('event_details', '<strong>This is a test</strong>', 'html');

any thoughts as to why I can not pass the HTML as a string received by a post?????

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

Are you working with a WYSIWYG Editor as textarea. If so, check if you are its real html you are passing. You could do that for example with var_dump($details). Maybe the tags have been removed with a htmlspecialchars call. In this case you would have to do a htmlspecialchars_decode() call. But without more information i am just guessing.

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

Hello,

As RamirezZ says, check HTML string. Seems there's something wrong within generated HTML.

Regards.

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

I have that fixed. I added a bit of code to your function addTemplateVariable

[code]public function addTemplateVariable($var, $value = '', $settings = '')
{
if($settings == 'html') //added by CH
{
$value= html_entity_decode($value);
}
$template = CreateTemplate::getInstance();
self::$log->info(
'Assign and replace text variable ' . $var . ' in template.'
);
$template->replaceVariable($var, $value, $settings);
}[/code]

This seemed to work well. The only issue I have now is when I generate the PDF. My images are not showing up. I have one large 8.5 x 11 jpg in the header of my word template as a background. I have two text boxes placed where I need my content that is entered by the user goes. My PDF shows a big red x. The image is at 300 dpi for printing purposes. Thoughts?