We use CSV data files which contain a field named @ChristmasMessage@ for our Christmas cards templates.
The problem is that for some records, these messages can be too long and not fit in the box provided. We then need to find a way to automatically reduce the font size so the @ChristmasMessage@ field can fit in the DIV box designed for this purpose. The default font size has been set to 12px and the width and height of the positioned div box are set to 500px and 350px respectively.
Can this be done with OL Connect? If so, how and can you please provide a demo template?
There is unfortunately no “simple” answer to this in the current version of Connect. This will require some scripting and most likely some amount of adjustment in order to get it right (hopefully, a “Copy Fitting” option will be available in a future version… I’ve requested it).
In the meantime, here’s somewhat of a script to help you out (I haven’t tested this - the syntax is correct but you’ll have to adjust numbers). You’ll have to create an ID for your positioned box and create a new script on that selector (aka #copy_fitting):
Thanks for this. It works in general but it is difficult to catch text overflows with this approach. Is it possible to use a WHILE statement instead to compare the height of the DIV box and the height of the text and gradually decrease the font size?
How can we get the height of the DIV box and the height of the Message with the below script as it doesn’t appear to be returning the values as it would if it was in a html page:
v```
ar font_size = font_size = parseInt($(“#MessageText”).css(“font-size”));
var container_height = parseInt($(“#MessageContainer”).css(“height”));
var text_height = parseInt($(“#MessageTextDiv”).css(“height”));