【发布时间】:2012-05-17 06:54:38
【问题描述】:
我正在使用 jquery.zclip 和 Symfony2 框架将文本复制到客户端的剪贴板。它工作正常,但撇号转换为 & # 0 3 9 ; (没有空格)
问题显然来自 Twig 模板引擎,该引擎将我的撇号转换为它们的 html 实体。
我想找到一个解决方案来阻止 Twig 这样做。或者在调用 zclip 之前将它们转回撇号?
你会怎么做?
这是我的 jquery/twig 代码:
<script>
$(document).ready(function(){
$('img#copy-description').zclip({
path:"{{ asset('bundles/yopyourownpoet/flash/ZeroClipboard.swf') }}",
copy:"{{ introLine1 }}{{ introLine2 }}{{ introLine3 }}{{ introLine4 }}{{ introLine5 }}",
afterCopy:function(){
alert('The poem has been copied to the clipboard.');
},
});
});
</script>
这段代码就变成了:
$(document).ready(function(){
$('img#copy-description').zclip({
path:"/yourownpoet/web/bundles/yopyourownpoet/flash/ZeroClipboard.swf",
copy:"Franz, hope Boston treats you wellDaddy, I have a story to tellIf you do not mindI'll promise it's kindLike the sweet ringing of a bell",
afterCopy:function(){
alert('The poem has been copied to the clipboard.');
},
});
编辑:我尝试了更多但也不起作用的方法:
function escape(string)
{
return string.replace("'", "'");
}
$('img#copy-description').zclip({
path:"{{ asset('bundles/yopyourownpoet/flash/ZeroClipboard.swf') }}",
copy: escape("{{ introLine1 }}")+"\n"+escape("{{ introLine2 }}")+"\n"+escape("{{ introLine3 }}")+"\n"+escape("{{ introLine4 }}")+"\n"+escape("{{ introLine5 }}"),
afterCopy:function(){
alert('The poem has been copied to the clipboard.');
},
});
但我仍然得到代码而不是撇号...
【问题讨论】: