Cheat sheet
Quick reference if you just need to know how to escape stuff!
Do's and Don'ts
- Use only
query_result_no_htmlandfetchByAssoc(..., -1, false)orfetchByAssocNoHtml, we don't want that peskyto_htmlfunction to be called - Do not generate html strings in php, use templates or
HtmlString::build - Do not echo html code in PHP, use Smarty
- Do not use
VStr::toJsAttrmethod - Do not try to build js code from PHP, use .js files or
<script>tags in templates - Do not use
html_entity_decode,htmlentities,htmlspecialchars,addslashes, it's probably not needed (unless you are working on legacy code) - Do not use
to_html,from_html,decode_html, these were always a bad idea
How to's:
| In | How do I handle... ? | ... like this: |
|
Smarty, html code |
standard variable | {$VARIABLE} |
| variable, but it's a HtmlString | {$VARIABLE} |
|
| variable, but it's a string and already html |
or
|
|
{capture} blocks |
|
|
|
|
||
|
Smarty, inside |
string variable | var myvar = '{$VARIABLE}'; |
| object or array variable | var mylist = {$VARIABLE|json_encode}; |
|
| string inside url |
|
|
|
Smarty, js in attributes |
string variable |
|
| string in url |
|