機能リファレンス
pieceofcake2/twig-view で使えるすべての Twig のフィルター、関数、テスト、タグです。
クイックナビゲーション
- フィルター - 値を変換します:
{{ value|filter }} - 関数 - 値を生成します:
{{ function() }} - テスト - 条件をチェックします:
{% if value is test %} - タグ - 制御構造です:
{% tag %} - CakePHP のヘルパー - ヘルパーにアクセスします:
{{ helper.method() }}
フィルター
Twig 3.x の組み込みフィルター
リファレンス: https://twig.symfony.com/doc/3.x/filters/index.html
absbatchcapitalizecolumnconvert_encodingcountry_namecurrency_namecurrency_symboldata_uridatedate_modifydefaultescape(エイリアス:e)filterfindfirstformatformat_currencyformat_dateformat_datetimeformat_numberformat_timehtml_to_markdowninline_cssinky_to_htmljoinjson_encodekeyslanguage_namelastlengthlocale_namelowermapmarkdown_to_htmlmergenl2brnumber_formatpluralrawreducereplacereverseroundshufflesingularsliceslugsortspacelesssplitstriptagstimezone_nametitletrimuupperurl_encode
文字列フィルター (cakephp/twig-view 由来)
実装済み:
tokenizeinsertclean_insert(エイリアス:cleanInsert)wrapwrap_block(エイリアス:wrapBlock)word_wrap(エイリアス:wordWrap)highlighttailtruncateexcerptto_list(エイリアス:toList)strip_links(エイリアス:stripLinks)
未実装:
substr- ❌ 代わりに Twig の組み込みのsliceフィルターを使ってください
語形変化フィルター (cakephp/twig-view 由来)
実装済み:
pluralizesingularizecamelizeunderscorehumanizetableizeclassifyvariableslug
数値フィルター (cakephp/twig-view 由来)
実装済み:
to_readable_sizeto_percentageformat_delta(エイリアス:formatDelta)currencyprecision
未実装:
number_format- ❌ 代わりに Twig の組み込みのnumber_formatフィルターまたはformat_numberフィルターを使ってください
ユーティリティフィルター (cakephp/twig-view 由来)
未実装:
utf8- ❌ ビューの責務ではありません。コントローラーで適切なエンコーディングのデータを用意してくださいascii- ❌ ビューの責務ではありません。コントローラーで適切なエンコーディングのデータを用意してくださいlow- ❌ Twig の組み込みのlowerフィルターを使ってください (後方互換性のため Legacy には残っています)up- ❌ Twig の組み込みのupperフィルターを使ってください (後方互換性のため Legacy には残っています)env- ❌ ビューの責務ではありません (後方互換性のため Legacy には残っています)serialize- ❌ ビューの責務ではありません。コントローラーでデータを用意してくださいunserialize- ❌ ビューの責務ではありません。コントローラーでデータを用意してくださいmd5- ❌ ビューの責務ではありません。コントローラーでデータを用意してくださいbase64_encode- ❌ ビューの責務ではありません。コントローラーでデータを用意してくださいbase64_decode- ❌ ビューの責務ではありません。コントローラーでデータを用意してくださいstring- ❌ 不要です。Twig が__toString()で自動的に変換しますis_multibyte- ❌ 代わりにmultibyteテストを使ってください:{% if text is multibyte %}
I18n フィルター (pieceofcake2/twig-view 独自)
trans
CakePHP ベースで、Symfony 風のインターフェイスです
レガシーフィルター (cakephp/legacy-twig-view:<2 - ⚠️ 非推奨)
未実装:
ago- ❌{{ time.timeAgoInWords(date) }}を使ってくださいsize- ❌to_readable_sizeを使ってくださいp- ❌precisionを使ってくださいcurr- ❌currencyを使ってくださいpct- ❌to_percentageを使ってくださいlow- ❌ Twig のlowerを使ってくださいup- ❌ Twig のupperを使ってくださいdebug- ❌ Twig のdump()を使ってくださいpr- ❌ Twig のdump()を使ってくださいenv- ❌ コントローラーから渡してください
関数
Twig 3.x の組み込み関数
リファレンス: https://twig.symfony.com/doc/3.x/functions/index.html
attributeblockconstantcountry_namescountry_timezonescurrency_namescycledatedumpenumenum_caseshtml_classeshtml_cvaincludelanguage_nameslocale_namesmaxminparentrandomrangescript_namessourcetemplate_from_stringtimezone_names
I18n 関数 (pieceofcake2/twig-view 独自)
実装済み:
____d__n__x
数値関数 (cakephp/twig-view 由来)
未実装:
default_currency- ❌ 代わりに{{ number.defaultCurrency() }}を使ってください
ビュー関数 (cakephp/twig-view 由来)
実装済み:
elementfetch
未実装 (cakephp/twig-view の ArraysExtension 由来):
in_array- ❌ Twig のin演算子を使ってください:{% if 'foo' in array %}explode- ❌ Twig のsplitフィルターを使ってください:{{ "a,b"|split(',') }}array- ❌ ビューの責務ではありません。コントローラーでデータを用意してくださいarray_push- ❌ Twig のmergeフィルターを使ってください:{{ array|merge(['new']) }}array_prev- ❌ ビューの責務ではありません。テンプレートではloop変数を使ってくださいarray_next- ❌ ビューの責務ではありません。テンプレートではloop変数を使ってくださいarray_current- ❌ ビューの責務ではありません。テンプレートではloop変数を使ってください
未実装 (cakephp/twig-view の TimeExtension 由来):
time- ❌ Twig の組み込みのdate関数を使ってくださいtimezones- ❌ ビューの責務ではありません。コントローラーでデータを用意してください
未実装 (cakephp/twig-view の UtilsExtension 由来):
uuid- ❌ ビューの責務ではありません。コントローラーまたはモデルで生成してください
ルーティング関数 (pieceofcake2/twig-view 独自)
urlpath
テスト
Twig 3.x の組み込みテスト
リファレンス: https://twig.symfony.com/doc/3.x/tests/index.html
カスタムテスト (cakephp/twig-view 由来)
実装済み:
multibyte
タグ
Twig 3.x の組み込みタグ
リファレンス: https://twig.symfony.com/doc/3.x/tags/index.html
applyautoescapeblockcachedeprecateddoembedextendsflushforfromguardifimportincludemacrosandboxsettypesuseverbatimwith
カスタムタグ (cakephp/twig-view 由来)
実装済み:
{% layout 'name' %}- レイアウトを設定します
カスタムタグ (pieceofcake2/twig-view 独自)
実装済み:
{% trans %}...{% endtrans %}- 翻訳ブロック (CakePHP ベースで、Symfony 風)
レガシー (cakephp/legacy-twig-view:<2)
未実装:
{% element 'name' %}- ❌ 代わりにelement()関数を使ってください
CakePHP のヘルパー
CakePHP のヘルパーを Twig テンプレートで使うには、コントローラーでヘルパーを有効にする必要があります。
コントローラーで有効にします: public $helpers = ['Html', 'Form', 'Time', 'Number', 'Text', 'Session', 'Paginator'];
命名: ヘルパーのクラス名は先頭が小文字の camelBack 形式の変数に変換されます (例: HtmlHelper::link() → {{ html.link() }}、MyCustomHelper::method() → {{ myCustom.method() }})
FlashHelper
フラッシュメッセージを描画します。
flash.render(key = 'flash', options = {})- フラッシュメッセージを描画します
FormHelper
フォームを作成し、入力要素を生成します。
form.create(model = null, options = {})- 開始フォームタグを作成しますform.end(options = null, secureAttributes = {})- フォームを閉じますform.input(fieldName, options = {})- 入力フィールドを生成しますform.inputs(fields = null, blacklist = null, options = {})- 複数の入力要素を生成しますform.label(fieldName, text = null, options = {})- label 要素を作成しますform.text(name, options = {})- テキスト入力を作成しますform.password(fieldName, options = {})- パスワード入力を作成しますform.hidden(fieldName, options = {})- hidden 入力を作成しますform.textarea(fieldName, options = {})- textarea を作成しますform.checkbox(fieldName, options = {})- チェックボックスを作成しますform.radio(fieldName, options, attributes = {})- ラジオボタンを作成しますform.select(fieldName, options, attributes = {})- セレクトボックス (ドロップダウン) を作成しますform.file(fieldName, options = {})- ファイルアップロードの入力を作成しますform.submit(caption = null, options = {})- 送信ボタンを作成しますform.button(title, options = {})- button 要素を作成しますform.postButton(title, url, options = {})- POST ボタンを作成しますform.postLink(title, url = null, options = {})- POST リンクを作成しますform.dateTime(fieldName, dateFormat = 'DMY', timeFormat = '12', attributes = {})- 日付と時刻のセレクトを作成しますform.year(fieldName, minYear, maxYear, attributes)- 年のセレクトを作成しますform.month(fieldName, attributes = {})- 月のセレクトを作成しますform.day(fieldName, attributes = {})- 日のセレクトを作成しますform.hour(fieldName, format24 = false, attributes = {})- 時のセレクトを作成しますform.minute(fieldName, attributes = {})- 分のセレクトを作成しますform.meridian(fieldName, attributes = {})- AM/PM のセレクトを作成します
HtmlHelper
HTML を生成し、マークアップを作成します。
html.charset(charset = null)- 文字エンコーディングの meta タグhtml.css(path, options = {})- CSS スタイルシートへのリンクhtml.meta(type, url = null, options = {})- meta タグを生成しますhtml.docType(type = 'xhtml-strict')- doctype タグを返しますhtml.style(data, oneline = true)- 配列から CSS を構築しますhtml.image(path, options = {})- 画像タグを作成しますhtml.link(title, url = null, options = {})- HTML のリンクを生成しますhtml.media(path, options)- audio/video タグを作成しますhtml.tag(tag, text, options)- テキストを HTML タグで囲みますhtml.div(class, text, options)- div 要素を作成しますhtml.para(class, text, options)- 段落要素を作成しますhtml.script(url, options)- JavaScript ファイルを読み込みますhtml.scriptBlock(code, options = {})- script ブロックを生成しますhtml.scriptStart(options = {})- スクリプトのバッファリングを開始しますhtml.scriptEnd()- スクリプトのバッファリングを終了しますhtml.nestedList(list, options = {}, itemOptions = {}, tag = 'ul')- 入れ子のリストを構築しますhtml.tableHeaders(names, trOptions = null, thOptions = null)- テーブルのヘッダーを作成しますhtml.tableCells(data, oddTrOptions = null, evenTrOptions = null, useCount = false, continueOddEven = true)- テーブルのセルを作成しますhtml.url(url = null, full = false)- URL を生成します
NumberHelper
数値を整形し、変換します。
number.currency(number, currency = 'USD', options = {})- 通貨として整形しますnumber.defaultCurrency(currency)- デフォルトの通貨を取得または設定しますnumber.addFormat(formatName, options)- カスタムの通貨フォーマットを追加しますnumber.precision(number, precision = 3)- 小数点以下の精度を指定して整形しますnumber.toPercentage(number, precision = 2, options = {})- パーセンテージに変換しますnumber.fromReadableSize(size, default)- "1 KB" をバイト数に変換しますnumber.toReadableSize(dataSize)- "1 KB"、"1 MB" などの形式に整形しますnumber.format(number, options = false)- オプションを指定して数値を整形しますnumber.formatDelta(number, options = {})- 符号付きの数値の差を整形します
PaginatorHelper
ページネーションをサポートします。
paginator.options(options = {})- ページネーションのオプションを設定しますpaginator.params(model = null)- ページネーションのパラメータを取得しますpaginator.param(key, model = null)- ページネーションのパラメータを 1 つ取得しますpaginator.url(options = {}, asArray = false, model = null)- ページネーションの URL を生成しますpaginator.defaultModel()- デフォルトのモデルを取得または設定しますpaginator.link(title, url = {}, options = {})- ページネーションのリンクを生成しますpaginator.prev(title = '<< Previous', options = {}, disabledTitle = null, disabledOptions = {})- 前へのリンクpaginator.next(title = 'Next >>', options = {}, disabledTitle = null, disabledOptions = {})- 次へのリンクpaginator.sort(key, title = null, options = {})- ソートのリンクを生成しますpaginator.sortDir(model = null, options = {})- ソートの方向を取得しますpaginator.sortKey(model = null, options = {})- ソートのキーを取得しますpaginator.numbers(options = {})- ページ番号を生成しますpaginator.first(first = '<< first', options = {})- 最初のページへのリンクpaginator.last(last = 'last >>', options = {})- 最後のページへのリンクpaginator.counter(options = {})- ページカウンター (例: "1-20 of 100")paginator.hasNext(model = null)- 次のページがあるかどうかをチェックしますpaginator.hasPrev(model = null)- 前のページがあるかどうかをチェックしますpaginator.hasPage(model = null, page = 1)- ページが存在するかどうかをチェックします
詳しい使い方は CakePHP のヘルパーの使い方 をご覧ください。
