jodeci
jodeci

Reputation: 996

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!

Upvotes: 4

Views: 4185

Answers (1)

Lukman
Lukman

Reputation: 19164

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'}

Upvotes: 8

Related Questions