I am attempting to display a "Read more" button if the length of a comment exceeds 80 characters. This is how I am checking it:
<tr repeat.for="m of comments">
<td if.bind="showLess">${m.comment.length < 80 ? m.comment : m.comment.substr(0,80) + " ... "}</td>
</tr>
So if the length is greater than 80, it shows the "..." at the end of the text.
However, I wanted to add a button after the dots, so I attempted this:
<td if.bind="showLess">${m.comment.length < 80 ? m.comment : m.comment.substr(0,80) + " ...<button>Read More</button> "}</td>
But this disrupted my HTML structure and displayed incorrectly as shown in the image below:
https://i.stack.imgur.com/DVZPn.png
How can I correctly structure the HTML within ${this function}? I cannot place the button outside the $ { } because it will appear even when the character count is less than 80.
Note: I opted not to use ellipsis as I require the exact character length.