开发者

Looking for variables which aren't assigned

开发者 https://www.devze.com 2022-12-28 01:06 出处:网络
What could happen if my template looks for variables which weren\'t assigned? For example: var id = \'{$tpl_id}\';

What could happen if my template looks for variables which weren't assigned?

For example:

var id = '{$tpl_id}';

This snippet is from my javascript code. I outputted the value and it 开发者_运维知识库is simply empty. I know I could use isset(). But I couldn't find anything about how Smarty handles non-existing variables. So, what happens if a template can't find a variable, because it wasn't assigned?


If a variable isn't defined, it's treated as if it were an empty variable. No (non-logic) error will occur.


Hy You have to use {literal} {/literal} Example:

{literal}
<script>
var id = '{/literal}{$tpl_id}{literal}';
// keep coding
</script>
{/literal}
0

精彩评论

暂无评论...
验证码 换一张
取 消