Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

do things with the return value of smarty function?

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!

like image 816
jodeci Avatar asked Feb 27 '23 19:02

jodeci


1 Answers

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'}
like image 78
Lukman Avatar answered Mar 02 '23 10:03

Lukman