Forum


Replies: 1   Views: 1262
Createfromtemplate, replacevariablebyhtml : apply template style
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 xiii29  · 10-01-2021 - 14:24

Hi,

FYI : I'm using the trial version of PhpDocX.

I would like to use a template in which I would like to replace content of some variables by HTML. It's working but I can't manage that content coming from HTML respect the original template style.

Here is an example :

$docx = new CreateDocxFromTemplate('template.docx');

// Template
$variables = array(
    'title' => 'Replace title',
    'txt' => 'Replace text'
);
$docx->replaceVariableByText($variables);

// Html
$html = '<h1> My Main Title </h1> <h2> Sub Title </h2> <h3> Sub sub title </h3> <p> Some text </p> <ul><li> Item 1 </li><li> Item 2 </li><li> Item 3 </li></ul>';
$docx->replaceVariableByHTML(
    'html', 
    'block',
    $html
);


// Save
$docx->createDocx('hello_world');

As a result, the title have a style but the one from the original doc ...

Any help ?

Thanks.