{"id":16619054,"url":"https://github.com/jasny/twig-extensions","last_synced_at":"2025-04-07T18:11:26.114Z","repository":{"id":56996827,"uuid":"11372964","full_name":"jasny/twig-extensions","owner":"jasny","description":"A number of useful filters for Twig","archived":false,"fork":false,"pushed_at":"2024-09-03T09:06:05.000Z","size":95,"stargazers_count":107,"open_issues_count":1,"forks_count":18,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-01T23:17:39.509Z","etag":null,"topics":["datetime","pcre","php","twig"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jasny.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-07-12T16:20:19.000Z","updated_at":"2024-11-26T06:32:59.000Z","dependencies_parsed_at":"2024-11-23T01:02:18.089Z","dependency_job_id":"0fdfa0a2-2be1-48fe-9be6-98202ad21e46","html_url":"https://github.com/jasny/twig-extensions","commit_stats":{"total_commits":57,"total_committers":7,"mean_commits":8.142857142857142,"dds":"0.26315789473684215","last_synced_commit":"0c1e2af272b2f448a693e0cee34ca3f41864a4ed"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasny%2Ftwig-extensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasny%2Ftwig-extensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasny%2Ftwig-extensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasny%2Ftwig-extensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jasny","download_url":"https://codeload.github.com/jasny/twig-extensions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247704569,"owners_count":20982298,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["datetime","pcre","php","twig"],"created_at":"2024-10-12T02:22:37.360Z","updated_at":"2025-04-07T18:11:26.086Z","avatar_url":"https://github.com/jasny.png","language":"PHP","readme":"Jasny Twig Extensions\n=======================\n\n[![PHP](https://github.com/jasny/twig-extensions/actions/workflows/php.yml/badge.svg)](https://github.com/jasny/twig-extensions/actions/workflows/php.yml)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/jasny/twig-extensions/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/jasny/twig-extensions/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/jasny/twig-extensions/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/jasny/twig-extensions/?branch=master)\n[![Packagist Stable Version](https://img.shields.io/packagist/v/jasny/twig-extensions.svg)](https://packagist.org/packages/jasny/twig-extensions)\n[![Packagist License](https://img.shields.io/packagist/l/jasny/twig-extensions.svg)](https://packagist.org/packages/jasny/twig-extensions)\n\nA number of useful filters for Twig.\n\n## Installation\n\nJasny's Twig Extensions can be easily installed using [composer](http://getcomposer.org/)\n\n    composer require jasny/twig-extensions\n\n## Usage\n\n```php\n$twig = new Twig_Environment($loader, $options);\n$twig-\u003eaddExtension(new Jasny\\Twig\\DateExtension());\n$twig-\u003eaddExtension(new Jasny\\Twig\\PcreExtension());\n$twig-\u003eaddExtension(new Jasny\\Twig\\TextExtension());\n$twig-\u003eaddExtension(new Jasny\\Twig\\ArrayExtension());\n```\n\nTo use in a Symfony project [register the extensions as a service](http://symfony.com/doc/current/cookbook/templating/twig_extension.html#register-an-extension-as-a-service).\n\n```yaml\nservices:\n  twig.extension.date:\n    class: Jasny\\Twig\\DateExtension\n    tags:\n      - { name: twig.extension }\n\n  twig.extension.pcre:\n    class: Jasny\\Twig\\PcreExtension\n    tags:\n      - { name: twig.extension }\n  \n  twig.extension.text:\n    class: Jasny\\Twig\\TextExtension\n    tags:\n      - { name: twig.extension }\n\n  twig.extension.array:\n    class: Jasny\\Twig\\ArrayExtension\n    tags:\n      - { name: twig.extension }\n```\n\n\n## Date extension\n\nFormat a date based on the current locale. Requires the [intl extension](http://www.php.net/intl).\n\n* localdate     - Format the date value as a string based on the current locale\n* localtime     - Format the time value as a string based on the current locale\n* localdatetime - Format the date/time value as a string based on the current locale\n* age           - Get the age (in years) based on a date\n* duration      - Get the duration string from seconds\n\n```php\nLocale::setDefault(LC_ALL, \"en_US\"); // vs \"nl_NL\"\n```\n\n```\n{{\"now\"|localdate('long')}}                 \u003c!-- July 12, 2013 --\u003e \u003c!-- 12 juli 2013 --\u003e\n{{\"now\"|localtime('short')}}                \u003c!-- 5:53 PM --\u003e \u003c!-- 17:53 --\u003e\n{{\"2013-10-01 23:15:00\"|localdatetime}}     \u003c!-- 10/01/2013 11:15 PM --\u003e \u003c!-- 01-10-2013 23:15 --\u003e\n{{\"22-08-1981\"|age}}                        \u003c!-- 35 --\u003e\n{{ 3600|duration }}                         \u003c!-- 1h --\u003e\n```\n\n\n## PCRE\n\nExposes [PCRE](http://www.php.net/pcre) to Twig.\n\n* preg_quote   - Quote regular expression characters\n* preg_match   - Perform a regular expression match\n* preg_get     - Perform a regular expression match and return the matched group\n* preg_get_all - Perform a regular expression match and return the group for all matches\n* preg_grep    - Perform a regular expression match and return an array of entries that match the pattern\n* preg_replace - Perform a regular expression search and replace\n* preg_filter  - Perform a regular expression search and replace, returning only matched subjects.\n* preg_split   - Split text into an array using a regular expression\n\n```\n{% if client.email|preg_match('/^.+@.+\\.\\w+$/') %}Email: {{ client.email }}{% endif %}\nWebsite: {{ client.website|preg_replace('~^https?://~')\nFirst name: {{ client.fullname|preg_get('/^\\S+/') }}\n\u003cul\u003e\n  {% for item in items|preg_split('/\\s+/')|preg_filter('/-test$/', 'invert') %}\n    \u003cli\u003e{{ item }}\u003c/li\u003e\n  {% endfor %}\n\u003c/ul\u003e\n```\n\n\n## Text ##\n\nConvert text to HTML + string functions\n\n* paragraph - Add HTML paragraph and line breaks to text\n* line - Get a single line of text\n* less - Cut of text on a page break\n* truncate - Cut off text if it's too long\n* linkify - Turn all URLs into clickable links (also supports Twitter @user and #subject)\n\n\n## Array ##\n\nBrings PHP's array functions to Twig\n\n* sum - Calculate the sum of values in an array\n* product - Calculate the product of values in an array\n* values - Return all the values of an array\n* as_array - Cast an object to an associated array\n* html_attr - Turn an array into an HTML attribute string\n","funding_links":[],"categories":["Twig"],"sub_categories":["Extensions"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasny%2Ftwig-extensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjasny%2Ftwig-extensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasny%2Ftwig-extensions/lists"}