admin管理员组

文章数量:1406918

We have this Smarty function that returns HTML code for templates. However it is also possible that the function returns a null string, which we now wish to identify. Our system has been running stably for years, so I am looking for the least invasive possible solution.

Is it possible to assign the return value to a smarty variable? I have tried assigning it to a Javascript variable, however, because part of the HTML is user generated, the return string could be a mixture of double and single quotes, which causes problems in IE (unfortunately the majority of our user base).

<script type="text/javascript">
var html = '{smarty function}'; //IE chokes on mixed quotes
</script>

Any help appreciated!

We have this Smarty function that returns HTML code for templates. However it is also possible that the function returns a null string, which we now wish to identify. Our system has been running stably for years, so I am looking for the least invasive possible solution.

Is it possible to assign the return value to a smarty variable? I have tried assigning it to a Javascript variable, however, because part of the HTML is user generated, the return string could be a mixture of double and single quotes, which causes problems in IE (unfortunately the majority of our user base).

<script type="text/javascript">
var html = '{smarty function}'; //IE chokes on mixed quotes
</script>

Any help appreciated!

Share Improve this question asked Jan 12, 2010 at 3:04 jodecijodeci 9962 gold badges11 silver badges18 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

Use escape modifier, for example:

{$variable|escape:'quotes'}

For smarty function, you can first try if {smarty_function|escape:'quotes'} works, if it doesn't then you have to assign the output of the function into a variable first before escaping it, and for that you use capture:

 {capture name=mycapture}{smarty_function}{/capture}
 {$smarty.capture.mycapture|escape:'quotes'}

本文标签: phpdo things with the return value of smarty functionStack Overflow