Jak debugować zmienne w Smarty jak w PHP var dump()

Mam kilka zmiennych w szablonie i nie wiem, gdzie je przypisałem. Muszę wiedzieć, co jest wewnątrz danej zmiennej; na przykład, powiedzmy, że mam zmienną w smarty o nazwie member. Próbowałem z {debug}, ale nie zadziałało i nie było wyświetlane wyskakujące okienko.

Jak mogę wypisać / debugować zmienne smarty używając czegoś takiego jak var_dump() wewnątrz szablonów?

Author: Nathaniel Ford, 2010-03-12

11 answers

Możesz używać tagów {php}

Metoda 1 (nie będzie działać w Smarty 3.1 lub nowszym):

{php}

$var =
$this->get_template_vars('var');
var_dump($var);

{/php}

Metoda 2:

{$var|@print_r}

Metoda 3:

{$var|@var_dump}
Daj mi znać, jeśli to pomoże.
 285
Author: pinaki,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-07-07 11:07:04

To powinno zadziałać:

{$var|@print_r}

Lub

{$var|@var_dump}

@ jest potrzebne dla tablic, aby smarty uruchomił modyfikator przeciwko całości, w przeciwnym razie robi to dla każdego elementu.

 111
Author: Tom Haigh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-11-28 11:01:15

Jeśli to coś warte, możesz zrobić {$varname|@debug_print_var}, aby uzyskać wyjście var_dump()-esque dla swojej zmiennej.

 22
Author: Chris,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-09-17 20:03:51

Po prostu użyj {debug} w swoim .tpl i spójrz na swój kod źródłowy

 8
Author: david,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-04-28 12:10:22

W nowym Smarty jest:

<pre>
{var_dump($variable)}
</pre>
 4
Author: Alexander Zakusilo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-03-06 19:46:42

Wypróbuj sesję Smarty:

{$smarty.session|@debug_print_var}

Lub

{$smarty.session|@print_r}

Aby upiększyć swój wynik, użyj go między <pre> </pre> znacznikami

 4
Author: karadayi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-07-02 10:45:30

Jeśli chcesz coś ładniejszego radzę

{"<?php\n\$data =\n"|@cat:{$yourvariable|@var_export:true|@cat:";\n?>"}|@highlight_string:true}

Wystarczy zastąpić zmienną zmienną

 2
Author: Bastilol,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-11-28 10:17:50

Spróbuj tego .... Ustaw $debugging Na TRUE w Smarty.

 1
Author: RubyDubee,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-03-12 09:54:33

W smarty V3 możesz użyć tego

{var_dump($variable)}

 1
Author: Awais fiaz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-02-15 12:12:25

W smarty jest wbudowany modyfikator, którego można użyć używając | (Operator pojedynczego potoku). W ten sposób {$varname|@print_r} wyświetli wartość jako print_r($php_variable)

 0
Author: Pranav Bhatt,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-01-09 10:19:30

Do debugowania w smarty w prestashop 1.6.x:

{ddd($variable)} -> debug and die

{ppp($variable)} -> debug only

An onther usefull debug tag:

{debug}
 0
Author: Aurelink,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-06-26 13:09:57