Question

I have tried to wrap HTML CMS content, but it fails.

Here the code I have tried:

<h3>Wrap Example</h3>
<cfset test='<h4><span>This is failure wrap function</span></h4><span><h5>This is failure wrap function</h5></span>'>
<cfoutput>#Wrap(test, 10)#</cfoutput>

The result is given below:

 Wrap Example

 This is failure wrap function< /span>

 This is failure wrap function< /h5>

How can fix this issue?

Was it helpful?

Solution

As per its docs, wrap() operates on a string, not a fragment of HTML. Whilst the latter is the former, the former does not imply any understanding of the latter. All wrap() sees is string data... it does not know that some of the string you are passing it is HTML, and accordingly one cannot simply interrupt an HTML tag with a line break character.

So basically there's nothing to "fix" here, as you're just using the inappropriate tool for the job.

I suspect what you should be looking at doing is putting the text within a span or a div or some other container tag, and then style that containing tag to have the width that you want. Chopping the string up into numbers-of-characters is not really how to approach the task you're wanting to accomplish, I think?

Why is it you're trying to do, in "wrapping" this mark-up at 10 characters?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top