slug
¶
The slug
filter transforms a given string into another string that
only includes safe ASCII characters.
slug フィルターは、指定された文字列を、安全な ASCII 文字のみを含む別の文字列に変換します。
Here is an example:
次に例を示します。
1 2 |
{{ 'Wôrķšƥáçè ~~sèťtïñğš~~'|slug }}
Workspace-settings
|
The default separator between words is a dash (-
), but you can
define a selector of your choice by passing it as an argument:
単語間のデフォルトのセパレーターはダッシュ (-) ですが、引数として渡すことで選択したセレクターを定義できます。
1 2 |
{{ 'Wôrķšƥáçè ~~sèťtïñğš~~'|slug('/') }}
Workspace/settings
|
The slugger automatically detects the language of the original string, but you can also specify it explicitly using the second argument:
スラッガーは元の文字列の言語を自動的に検出しますが、2 番目の引数を使用して明示的に指定することもできます。
1 |
{{ '...'|slug('-', 'ko') }}
|
The slug
filter uses the method by the same name in Symfony's
AsciiSlugger.
slug フィルターは、Symfony の AsciiSlugger にある同名のメソッドを使用します。
Note
ノート
The slug
filter is part of the StringExtension
which is not
installed by default. Install it first:
slug フィルターは、デフォルトではインストールされない StringExtension の一部です。最初にインストールします。
1 |
$ composer require twig/string-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\String\StringExtension;
$twig = new \Twig\Environment(...);
$twig->addExtension(new StringExtension());
|
Arguments ¶
separator
: The separator that is used to join words (defaults to-
)セパレーター: 単語を結合するために使用されるセパレーター (デフォルトは -)locale
: The locale of the original string (if none is specified, it will be automatically detected)locale: 元の文字列のロケール (何も指定されていない場合は、自動的に検出されます)