Skip to content
This is the documentation for pieceofcake2/twig-view, a CakePHP 2.x plugin for pieceofcake2/cakephp. About this fork.

Complete Feature Reference ​

All available Twig filters, functions, tests, and tags in pieceofcake2/twig-view.

Quick Navigation ​

  • Filters - Transform values: {{ value|filter }}
  • Functions - Generate values: {{ function() }}
  • Tests - Check conditions: {% if value is test %}
  • Tags - Control structures: {% tag %}
  • CakePHP Helpers - Access helpers: {{ helper.method() }}

Filters ​

Twig 3.x Built-in Filters ​

Reference: https://twig.symfony.com/doc/3.x/filters/index.html

String Filters (from cakephp/twig-view) ​

Implemented:

  • tokenize
  • insert
  • clean_insert (alias: cleanInsert)
  • wrap
  • wrap_block (alias: wrapBlock)
  • word_wrap (alias: wordWrap)
  • highlight
  • tail
  • truncate
  • excerpt
  • to_list (alias: toList)
  • strip_links (alias: stripLinks)

Not Implemented:

  • substr - ❌ Use Twig's built-in slice filter instead

Inflection Filters (from cakephp/twig-view) ​

Implemented:

  • pluralize
  • singularize
  • camelize
  • underscore
  • humanize
  • tableize
  • classify
  • variable
  • slug

Number Filters (from cakephp/twig-view) ​

Implemented:

  • to_readable_size
  • to_percentage
  • format_delta (alias: formatDelta)
  • currency
  • precision

Not Implemented:

  • number_format - ❌ Use Twig's built-in number_format or format_number filter instead

Utility Filters (from cakephp/twig-view) ​

Not Implemented:

  • utf8 - ❌ Not a view concern, prepare data in controller with proper encoding
  • ascii - ❌ Not a view concern, prepare data in controller with proper encoding
  • low - ❌ Use Twig's built-in lower filter (kept in Legacy for backward compatibility)
  • up - ❌ Use Twig's built-in upper filter (kept in Legacy for backward compatibility)
  • env - ❌ Not a view concern (kept in Legacy for backward compatibility)
  • serialize - ❌ Not a view concern, prepare data in controller
  • unserialize - ❌ Not a view concern, prepare data in controller
  • md5 - ❌ Not a view concern, prepare data in controller
  • base64_encode - ❌ Not a view concern, prepare data in controller
  • base64_decode - ❌ Not a view concern, prepare data in controller
  • string - ❌ Not needed, Twig auto-converts with __toString()
  • is_multibyte - ❌ Use multibyte test instead: {% if text is multibyte %}

I18n Filters (pieceofcake2/twig-view original) ​

  • trans

CakePHP-based, Symfony-like interface

Legacy Filters (cakephp/legacy-twig-view:<2 - ⚠️ DEPRECATED) ​

Not Implemented:

  • ago - ❌ Use {{ time.timeAgoInWords(date) }}
  • size - ❌ Use to_readable_size
  • p - ❌ Use precision
  • curr - ❌ Use currency
  • pct - ❌ Use to_percentage
  • low - ❌ Use Twig's lower
  • up - ❌ Use Twig's upper
  • debug - ❌ Use Twig's dump()
  • pr - ❌ Use Twig's dump()
  • env - ❌ Pass from controller

Functions ​

Twig 3.x Built-in Functions ​

Reference: https://twig.symfony.com/doc/3.x/functions/index.html

I18n Functions (pieceofcake2/twig-view original) ​

Implemented:

  • __
  • __d
  • __n
  • __x

Number Functions (from cakephp/twig-view) ​

Not Implemented:

  • default_currency - ❌ Use {{ number.defaultCurrency() }} instead

View Functions (from cakephp/twig-view) ​

Implemented:

  • element
  • fetch

Not Implemented (from cakephp/twig-view ArraysExtension):

  • in_array - ❌ Use Twig's in operator: {% if 'foo' in array %}
  • explode - ❌ Use Twig's split filter: {{ "a,b"|split(',') }}
  • array - ❌ Not a view concern, prepare data in controller
  • array_push - ❌ Use Twig's merge filter: {{ array|merge(['new']) }}
  • array_prev - ❌ Not a view concern, use loop variable in templates
  • array_next - ❌ Not a view concern, use loop variable in templates
  • array_current - ❌ Not a view concern, use loop variable in templates

Not Implemented (from cakephp/twig-view TimeExtension):

  • time - ❌ Use Twig's built-in date function
  • timezones - ❌ Not a view concern, prepare data in controller

Not Implemented (from cakephp/twig-view UtilsExtension):

  • uuid - ❌ Not a view concern, generate in controller/model

Routing Functions (pieceofcake2/twig-view original) ​

  • url
  • path

Tests ​

Twig 3.x Built-in Tests ​

Reference: https://twig.symfony.com/doc/3.x/tests/index.html

Custom Tests (from cakephp/twig-view) ​

Implemented:

  • multibyte

Tags ​

Twig 3.x Built-in Tags ​

Reference: https://twig.symfony.com/doc/3.x/tags/index.html

Custom Tags (from cakephp/twig-view) ​

Implemented:

  • {% layout 'name' %} - Set layout

Custom Tags (pieceofcake2/twig-view original) ​

Implemented:

  • {% trans %}...{% endtrans %} - Translation block (CakePHP-based, Symfony-like)

Legacy (cakephp/legacy-twig-view:<2) ​

Not Implemented:

  • {% element 'name' %} - ❌ Use element() function instead

CakePHP Helpers ​

CakePHP Helpers must be enabled in your controller to be available in Twig templates.

Enable in controller: public $helpers = ['Html', 'Form', 'Time', 'Number', 'Text', 'Session', 'Paginator'];

Naming: Helper class names are converted to lowercase (e.g., HtmlHelper::link() → {{ html.link() }}, MyCustomHelper::method() → {{ mycustom.method() }})

FlashHelper ​

Flash message rendering.

  • flash.render(key = 'flash', options = {}) - Render flash message

FormHelper ​

Form creation and input generation.

  • form.create(model = null, options = {}) - Create opening form tag
  • form.end(options = null, secureAttributes = {}) - Close form
  • form.input(fieldName, options = {}) - Generate input field
  • form.inputs(fields = null, blacklist = null, options = {}) - Generate multiple inputs
  • form.label(fieldName, text = null, options = {}) - Create label element
  • form.text(name, options = {}) - Create text input
  • form.password(fieldName, options = {}) - Create password input
  • form.hidden(fieldName, options = {}) - Create hidden input
  • form.textarea(fieldName, options = {}) - Create textarea
  • form.checkbox(fieldName, options = {}) - Create checkbox
  • form.radio(fieldName, options, attributes = {}) - Create radio buttons
  • form.select(fieldName, options, attributes = {}) - Create select dropdown
  • form.file(fieldName, options = {}) - Create file upload input
  • form.submit(caption = null, options = {}) - Create submit button
  • form.button(title, options = {}) - Create button element
  • form.postButton(title, url, options = {}) - Create POST button
  • form.postLink(title, url = null, options = {}) - Create POST link
  • form.dateTime(fieldName, dateFormat = 'DMY', timeFormat = '12', attributes = {}) - Create date/time selects
  • form.year(fieldName, minYear, maxYear, attributes) - Create year select
  • form.month(fieldName, attributes = {}) - Create month select
  • form.day(fieldName, attributes = {}) - Create day select
  • form.hour(fieldName, format24 = false, attributes = {}) - Create hour select
  • form.minute(fieldName, attributes = {}) - Create minute select
  • form.meridian(fieldName, attributes = {}) - Create AM/PM select

HtmlHelper ​

HTML generation and markup creation.

  • html.charset(charset = null) - Meta tag for character encoding
  • html.css(path, options = {}) - Link to CSS stylesheet(s)
  • html.meta(type, url = null, options = {}) - Generate meta tags
  • html.docType(type = 'xhtml-strict') - Return doctype tag
  • html.style(data, oneline = true) - Build CSS from array
  • html.image(path, options = {}) - Create image tag
  • html.link(title, url = null, options = {}) - Generate HTML link
  • html.media(path, options) - Create audio/video tag
  • html.tag(tag, text, options) - Wrap text in HTML tag
  • html.div(class, text, options) - Create div element
  • html.para(class, text, options) - Create paragraph element
  • html.script(url, options) - Include JavaScript file(s)
  • html.scriptBlock(code, options = {}) - Generate script block
  • html.scriptStart(options = {}) - Begin script buffering
  • html.scriptEnd() - End script buffering
  • html.nestedList(list, options = {}, itemOptions = {}, tag = 'ul') - Build nested list
  • html.tableHeaders(names, trOptions = null, thOptions = null) - Create table headers
  • html.tableCells(data, oddTrOptions = null, evenTrOptions = null, useCount = false, continueOddEven = true) - Create table cells
  • html.url(url = null, full = false) - Generate URL

NumberHelper ​

Number formatting and conversion.

  • number.currency(number, currency = 'USD', options = {}) - Format as currency
  • number.defaultCurrency(currency) - Get/set default currency
  • number.addFormat(formatName, options) - Add custom currency format
  • number.precision(number, precision = 3) - Format with decimal precision
  • number.toPercentage(number, precision = 2, options = {}) - Convert to percentage
  • number.fromReadableSize(size, default) - Convert "1 KB" to bytes
  • number.toReadableSize(dataSize) - Format as "1 KB", "1 MB", etc.
  • number.format(number, options = false) - Format number with options
  • number.formatDelta(number, options = {}) - Format signed number difference

PaginatorHelper ​

Pagination support.

  • paginator.options(options = {}) - Set pagination options
  • paginator.params(model = null) - Get pagination params
  • paginator.param(key, model = null) - Get single pagination param
  • paginator.url(options = {}, asArray = false, model = null) - Generate pagination URL
  • paginator.defaultModel() - Get/set default model
  • paginator.link(title, url = {}, options = {}) - Generate pagination link
  • paginator.prev(title = '<< Previous', options = {}, disabledTitle = null, disabledOptions = {}) - Previous link
  • paginator.next(title = 'Next >>', options = {}, disabledTitle = null, disabledOptions = {}) - Next link
  • paginator.sort(key, title = null, options = {}) - Generate sort link
  • paginator.sortDir(model = null, options = {}) - Get sort direction
  • paginator.sortKey(model = null, options = {}) - Get sort key
  • paginator.numbers(options = {}) - Generate page numbers
  • paginator.first(first = '<< first', options = {}) - First page link
  • paginator.last(last = 'last >>', options = {}) - Last page link
  • paginator.counter(options = {}) - Page counter (e.g., "1-20 of 100")
  • paginator.hasNext(model = null) - Check if next page exists
  • paginator.hasPrev(model = null) - Check if previous page exists
  • paginator.hasPage(model = null, page = 1) - Check if page exists

See Using CakePHP Helpers for detailed usage guide.

See Also ​

See LICENSE for copyright and license information. Not affiliated with the Cake Software Foundation.