Applying bold to variable text

I have a huge text that is variable for each object, but I need to apply bold when the word “INVOICE” and “PAYMENT” occur.
How do I proceed?

When the value has been allocated to a record field then you can insert the following Handlebars expression when viewing the Print Section in Source mode:

{{applyBoldText fieldName}}

Tip: Make sure to replace fieldName with the correct record field name.

And apply the following Handlebars helper to search for the words “INVOICE” and “PAYMENT” and, if found, to wrap these words in a <span>-element to which the CSS font-weight: bold; has been applied:

Control Script

Name: Example

Handlebars.registerHelper("applyBoldText", function (val) {
	let result = "";
	
	if (val !== "") {
		result = val.replace(/(INVOICE|PAYMENT)/gi, "<span style=\"font-weight: bold;\">$1</span>");
	}
	
	return new Handlebars.SafeString(result);
});

Thanks for your help.
I tried a few ways to get this solution to work, but I couldn’t.
The screen shots below show some errors of what I did wrong.
111

Can you let us know please which version of PlanetPress Connect or PReS Connect you have currently installed? The reason why I am asking is because I assume that these errors occur because the Handlebars feature was not yet implemented in the version you have currently installed.

Version 2021.1.1.6675

333

As for PReS Connect version 2021.1.1, I assume that you could apply something like the following instead:

HTML

<span class="apply-bold-text" style="font-size: 11pt;">@teste@</span>

Standard Script

Name: Apply bold text
Selector: span.apply-bold-text

var field = "";
var result = "";

// TIP: Make sure to replace 'fieldName' with the correct field name
field = record.fields.fieldName;

if (field !== "") {
	result = field.replace(/(INVOICE|PAYMENT)/gi, "<span style=\"font-weight: bold;\">$1</span>");
}

results.html(result);
1 Like

Thank you very much, @Marten . The script worked perfectly.

1 Like