Forum


Replies: 4   Views: 4116
Highlight/background color for templatevariable
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 Andrew Goodricke  · 16-10-2013 - 17:13

I'm trying to get a variable to have a different background dependant upon the value.

e.g. 1 would be red, 2 would be orange and 3 would be green.




I've tried doing:
$code = '<head><style type="text/css">body{font-family: Arial;font-size:11pt;background-color: yellow;}</style></head><body>9</body>';
$docx->addTemplateVariable('FIELD_BK',$code, 'html');


but this doesn't do anything.  Any pointers would be greatfully received.



Thanks.


Posted by jorgelj  · 17-10-2013 - 09:28

Hello,



I recommend you replaceTemplateVariableByHtml. Please try this code:



$html = '<span style="font-family: Arial;font-size:11pt;background-color: yellow;">9</span>';

$docx->replaceTemplateVariableByHtml('FIELD_BK', 'inline', $html);



Regards.


Posted by Andrew Goodricke  · 17-10-2013 - 10:45

Hi,



thanks for the reponse, I switched over to using:




$html = '<span style="font-family: Arial;font-size:11pt;background-color: yellow;">9</span>';
$docx->replaceTemplateVariableByHTML('FIELD_BK', 'inline', $html);


but I still don't get a highlighted background.



I tried setting the colour with a #ffff00 with the same result.  Any other suggestions would be greatly welcomed.


Posted by jorgelj  · 18-10-2013 - 08:18

Hello,



Sorry, background-color is supported by <p> (and other tags like tables, lists...). This is a tested example:



$html = '<p style="font-family: Arial;font-size:11pt;background-color: yellow;">9</p>';

$docx->replaceTemplateVariableByHTML('FIELD_BK', 'inline', $html);



Regards.