dump

The dump function dumps information about a template variable. This is mostly useful to debug a template that does not behave as expected by introspecting its variables:

dump 関数は、テンプレート変数に関する情報をダンプします。これは、変数を調べて期待どおりに動作しないテンプレートをデバッグするのに最も役立ちます。
1
{{ dump(user) }}

Note

ノート

The dump function is not available by default. You must add the \Twig\Extension\DebugExtension extension explicitly when creating your Twig environment:

デフォルトでは、ダンプ機能は使用できません。 Twigenvironment を作成するときに、\Twig\Extension\DebugExtension エクステンションを明示的に追加する必要があります。
1
2
3
4
5
$twig = new \Twig\Environment($loader, [
    'debug' => true,
    // ...
]);
$twig->addExtension(new \Twig\Extension\DebugExtension());

Even when enabled, the dump function won't display anything if the debug option on the environment is not enabled (to avoid leaking debug information on a production server).

ダンプ機能が有効になっていても、環境のデバッグ オプションが有効になっていない場合は何も表示されません (実稼働サーバーでデバッグ情報が漏洩するのを避けるため)。

In an HTML context, wrap the output with a pre tag to make it easier to read:

HTML コンテキストでは、出力を pre タグで囲み、読みやすくします。
1
2
3
<pre>
    {{ dump(user) }}
</pre>

Tip

ヒント

Using a pre tag is not needed when XDebug is enabled and html_errors is on; as a bonus, the output is also nicer with XDebug enabled.

XDebug が有効で、html_errors がオンの場合、pre タグを使用する必要はありません。おまけとして、XDebug を有効にすると、出力も向上します。

You can debug several variables by passing them as additional arguments:

追加の引数として渡すことで、いくつかの変数をデバッグできます。
1
{{ dump(user, categories) }}

If you don't pass any value, all variables from the current context are dumped:

値を渡さない場合、現在のコンテキストのすべての変数がダンプされます。
1
{{ dump() }}

Note

ノート

Internally, Twig uses the PHP var_dump function.

内部的に、Twig は PHP の var_dump 関数を使用します。

Arguments

  • context: The context to dump
    context: ダンプするコンテキスト