Currently, I am facing a challenge in dynamically adjusting the width value for a <div>
element serving as a coloured bar within an HTML template used for PDF generation. While I can successfully set other values using something like {{my_value}}
, applying a similar approach to style attributes does not yield the desired outcome.
My attempts have included using width: {{my_value}}%
and assigning a class to the div with a specified width i.e.
.divClass { "width": {{my_value}} }
The HTML template snippet is shown below:
<!-- Dynamically update width based on {{my_value}} -->
<div style="width: 45% !important;">
<!-- Dynamic percentage displayed inside and beside -->
<div style="padding-left:8px;">{{my_value}}%</div>
</div>
Within the JavaScript file, we have the following code segment:
// Retrieve the value from POST request
var val1 = req.body.val1;
//substitute the value in the template
templateHtml = templateHtml.replace('{{my_value}}', val1);
In essence, if the POST val1 = 20%
, my goal is to ensure that the coloured bar <div>
reflects only 20% of its total width while also displaying the corresponding percentage. However, at present, although I can display the percentage on the bar, it ends up filling the entire width with color instead.