How to Debug Variables in Smarty like in PHP var_dump()

后端 未结 13 521
别那么骄傲
别那么骄傲 2020-12-22 16:13

I have some variables inside a template and I don\'t know where I assigned them. I need to know what is inside a particular variable; for instance, say I have a variable in

相关标签:
13条回答
  • 2020-12-22 16:22

    try this .... Set $debugging to TRUE in Smarty.

    0 讨论(0)
  • 2020-12-22 16:25

    In new Smarty it is:

    <pre>
    {var_dump($variable)}
    </pre>
    
    0 讨论(0)
  • 2020-12-22 16:28

    This should work:

    {$var|@print_r}
    

    or

    {$var|@var_dump}
    

    The @ is needed for arrays to make smarty run the modifier against the whole thing, otherwise it does it for each element.

    0 讨论(0)
  • just use {debug} in your .tpl and look at your sourcecode

    0 讨论(0)
  • 2020-12-22 16:31

    I prefer to use <script>console.log({$varname|@json_encode})</script> to log to the console.

    0 讨论(0)
  • 2020-12-22 16:33

    You can use {php} tags

    Method 1 (won't work in Smarty 3.1 or later):

    {php}
    
    $var =
    $this->get_template_vars('var');
    var_dump($var);
    
    {/php}
    

    Method 2:

    {$var|@print_r}
    

    Method 3:

    {$var|@var_dump}
    
    0 讨论(0)
提交回复
热议问题