data_uri
¶
The data_uri
filter generates a URL using the data scheme as defined in
RFC 2397:
data_uri フィルターは、RFC 2397 で定義されているデータ スキームを使用して URL を生成します。
1 2 3 4 5 6 7 8 9 10 11 12 |
{{ image_data|data_uri }}
{{ source('path_to_image')|data_uri }}
{# force the mime type, disable the guessing of the mime type #}
{{ image_data|data_uri(mime="image/svg") }}
{# also works with plain text #}
{{ '<b>foobar</b>'|data_uri(mime="text/html") }}
{# add some extra parameters #}
{{ '<b>foobar</b>'|data_uri(mime="text/html", parameters={charset: "ascii"}) }}
|
Note
ノート
The data_uri
filter is part of the HtmlExtension
which is not
installed by default. Install it first:
data_uri フィルターは、デフォルトではインストールされない HtmlExtension の一部です。最初にインストールします。
1 |
$ composer require twig/html-extra
|
Then, on Symfony projects, install the twig/extra-bundle
:
次に、Symfony プロジェクトで、twig/extra-bundle をインストールします。
1 |
$ composer require twig/extra-bundle
|
Otherwise, add the extension explicitly on the Twig environment:
それ以外の場合は、Twig 環境で拡張機能を明示的に追加します。
1 2 3 4 |
use Twig\Extra\Html\HtmlExtension;
$twig = new \Twig\Environment(...);
$twig->addExtension(new HtmlExtension());
|
Note
ノート
The filter does not perform any length validation on purpose (limit depends on the usage context), validation should be done before calling this filter.
フィルターは、意図的に長さの検証を実行しません (制限は使用状況によって異なります)。検証は、このフィルターを呼び出す前に実行する必要があります。
Arguments ¶
mime
: The mime typemime: MIME タイプparameters
: An array of parametersparameters: パラメータの配列