Wrap在Coldfusion中对html内容失败 [英] Wrap fails for html content in Coldfusion

查看:339
本文介绍了Wrap在Coldfusion中对html内容失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图封装html CMS内容。

  



< < h3>包装示例< / h3>
< cfset test ='< h4>< span>这是故障换行函数< / span>< / h4>< span>< h5& ; / span>'>
< cfoutput> #Wrap(test,10)#< / cfoutput>

结果如下,

 包装示例

这是故障包装函数< / span>

这是故障绕回函数< / h5>

有人知道如何解决这个问题吗?

解决方案

根据其文档 wrap()字符串上操作,而不是的分段。虽然后者是前者,但前者并不暗示对后者的任何理解。所有 wrap()看到的是字符串数据...它不知道你传递的一些字符串是HTML,因此不能简单地中断一个HTML标签一个换行字符。



因此,基本上没有什么可以修复在这里,因为你只是使用不适当的工具。



我可疑您应该看到的是将文本放在 span div 或一些其他容器标签,然后包含标签的样式具有所需的宽度。把字符串切割成字符数并不是真正想要完成的任务,我想?



为什么要尝试做什么,在包装这个标记在10个字符?


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>

Do anyone know how can fix this issue?

解决方案

As per its docs, wrap() operates on a string, not a frangment 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?

这篇关于Wrap在Coldfusion中对html内容失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆