{"id":37004173,"url":"https://github.com/creative-sizzle/wn-twigextensions-plugin","last_synced_at":"2026-01-14T00:36:55.386Z","repository":{"id":56958917,"uuid":"409363023","full_name":"creative-sizzle/wn-twigextensions-plugin","owner":"creative-sizzle","description":"Twig extensions plugin for Winter CMS","archived":true,"fork":true,"pushed_at":"2021-11-24T21:00:26.000Z","size":161,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-12-10T10:18:09.698Z","etag":null,"topics":["wintercms-plugin"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"ericp-mrel/oc-twigextensions-plugin","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/creative-sizzle.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}},"created_at":"2021-09-22T21:36:00.000Z","updated_at":"2023-01-27T20:05:59.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/creative-sizzle/wn-twigextensions-plugin","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/creative-sizzle/wn-twigextensions-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creative-sizzle%2Fwn-twigextensions-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creative-sizzle%2Fwn-twigextensions-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creative-sizzle%2Fwn-twigextensions-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creative-sizzle%2Fwn-twigextensions-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/creative-sizzle","download_url":"https://codeload.github.com/creative-sizzle/wn-twigextensions-plugin/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creative-sizzle%2Fwn-twigextensions-plugin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406520,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["wintercms-plugin"],"created_at":"2026-01-14T00:36:54.727Z","updated_at":"2026-01-14T00:36:55.355Z","avatar_url":"https://github.com/creative-sizzle.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Twig extensions\n\n[![Build Status](https://travis-ci.org/vojtasvoboda/oc-twigextensions-plugin.svg?branch=master)](https://travis-ci.org/vojtasvoboda/oc-twigextensions-plugin)\n[![Codacy](https://img.shields.io/codacy/c6b23b6527bd407092763cace324ef4a.svg)](https://www.codacy.com/app/vojtasvoboda/oc-twigextensions-plugin)\n[![Scrutinizer Coverage](https://img.shields.io/scrutinizer/g/vojtasvoboda/oc-twigextensions-plugin.svg)](https://scrutinizer-ci.com/g/vojtasvoboda/oc-twigextensions-plugin/?branch=master)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/vojtasvoboda/oc-twigextensions-plugin/blob/master/LICENSE)\n\nTwig extensions plugin for OctoberCMS adds new filter and functions to your templates. No other plugin dependencies.\n\nTested with the latest stable OctoberCMS build 420 (with Laravel 5.5). For Laravel 5.4 use special branch `laravel54`.\n\n## Installation\n\nInstall plugin from CMS backend or by Composer:\n\n```\ncomposer require creative-sizzle/wn-twigextensions-plugin\n```\n\nThan you can use newly added filters/functions at your templates:\n\n```\n\u003ch1 class=\"heading\"\u003e{{ article.heading | uppercase }}\u003c/h1\u003e\n\u003cp class=\"created\"\u003e\n\tPosted at {{ article.date | strftime('%d.%m.%Y %H:%M:%S') }}\n\u003c/p\u003e\n\u003cp class=\"perex\"\u003e\n\t{{ article.perex | truncate(80) }}\n\u003c/p\u003e\n```\n\n## Available functions\n\n[config](https://laravel.com/docs/5.0/configuration#accessing-configuration-values), [env](https://laravel.com/docs/5.8/helpers#method-env), [session](https://laravel.com/docs/5.0/session#session-usage), [trans](https://octobercms.com/docs/plugin/localization), [var_dump](http://php.net/manual/en/function.var-dump.php), [template\\_from\\_string](http://twig.sensiolabs.org/doc/functions/template_from_string.html)\n\n### config\n\nFunction move the functionality of the Laravel `config()` helper function to Twig.\n\n```\n{{ config('app.locale') }}\n```\nThe example would output the value currently stored in `app.locale`.\nSee [more about the Laravel config helper function here](https://laravel.com/docs/5.0/configuration#accessing-configuration-values).\n\n### env\n\nFunction move the functionality of the Laravel `env()` helper function to Twig.\n\n```\n{{ env('APP_ENV', 'production') }}\n```\n\nThe example would output the value currently stored in `APP_ENV` environment variable. Second parameter is default value, when ENV key does not exists.\n\n### session\n\nFunction move the functionality of the Laravel `session()` helper function to Twig.\n\n```\n{{ session('my.session.key') }}\n```\nThe example would output the value currently stored in `my.session.key`.\nSee [more about the Laravel session helper function here](https://laravel.com/docs/5.0/session#session-usage).\n\n### trans\n\nFunction move the functionality of the Laravel `trans()` helper function to Twig.\n\n```\n{{ trans('acme.blog::lang.app.name') }}\n```\nThe example would output a value stored in a localization file of an imaginary blog plugin.\nSee [more about localization in October CMS here](https://octobercms.com/docs/plugin/localization).\n\n### var_dump\n\nDumps information about a variable. Can be also used as filter.\n\n```\n\u003cpre\u003e{{ var_dump(users) }}\u003c/pre\u003e\n```\n\n### template\\_from\\_string\n\nFunction loads a template from a string.\n\n```\n{% set name = 'John' %}\n{{ include(template_from_string(\"Hello {{ name }}\")) }}\n{{ include(template_from_string(\"Hurry up it is: {{ \"now\"|date(\"m/d/Y\") }}\")) }}\n```\n\n## Available filters\n\nstrftime, uppercase, lowercase, ucfirst, lcfirst, ltrim, rtrim, str\\_repeat,\nplural, truncate, wordwrap, strpad, str_replace, strip_tags, leftpad, rightpad, rtl, shuffle, time\\_diff,\nlocalizeddate, localizednumber, localizedcurrency, mailto, var\\_dump, revision, sortbyfield\n\n### strftime\n\nFormat a local time/date according to locale settings.\n\n```\nPosted at {{ article.date | strftime('%d.%m.%Y %H:%M:%S') }}\n```\n\nThe example would output *Posted at 04.01.2016 22:57:42*. See [more format parameters](http://php.net/manual/en/function.strftime.php#refsect1-function.strftime-parameters).\n\n### uppercase\n\nMake a string uppercase.\n\n```\nHello I'm {{ 'Jack' | uppercase }}\n```\n\nThe example would output *Hello I'm JACK*.\n\n### lowercase\n\nMake a string lowercase.\n\n```\nHello I'm {{ 'JACK' | lowercase }}\n```\n\nThe example would output *Hello I'm jack*.\n\n### ucfirst\n\nMake a string's first character uppercase.\n\n```\nHello I'm {{ 'jack' | ucfirst }}\n```\n\nThe example would output *Hello I'm Jack*.\n\n### lcfirst\n\nMake a string's first character lowercase.\n\n```\nHello I'm {{ 'Jack' | lcfirst }}\n```\n\nThe example would output *Hello I'm jack*.\n\n### ltrim\n\nStrip whitespace (or other characters) from the beginning of a string.\n\n```\nHello I'm {{ ' jack' | ltrim }}\n```\n\nThe example would output *Hello I'm jack* without whitespaces from the start.\n\n### rtrim\n\nStrip whitespace (or other characters) from the end of a string.\n\n```\nHello I'm {{ 'jack ' | rtrim }}\n```\n\nThe example would output *Hello I'm jack* without whitespaces from the end.\n\n### str_repeat\n\nRepeat a string.\n\n```\nI'm the {{ 'best' | str_repeat(3) }}!\n```\n\nThe example would output *I'm the best best best!*\n\n### plural\n\nGet the plural form of an English word.\n\n```\nYou have {{ count }} new {{ 'mail' | plural(count) }}\n```\n\nThe example would output *You have 1 new mail* or *You have 3 new mails* - depending on mails count.\n\n### truncate\n\nUse the truncate filter to cut off a string after limit is reached.\n\n```\n{{ \"Hello World!\" | truncate(5) }}\n```\n\nThe example would output *Hello...*, as ... is the default separator.\n\nYou can also tell truncate to preserve whole words by setting the second parameter to true. If the last Word is on the the separator, truncate will print out the whole Word.\n\n```\n{{ \"Hello World!\" | truncate(7, true) }}\n```\n\nHere *Hello World!* would be printed.\n\nIf you want to change the separator, just set the third parameter to your desired separator.\n\n```\n{{ \"Hello World!\" | truncate(7, false, \"??\") }}\n```\n\nThis example would print *Hello W??*.\n\n### wordwrap\n\nUse the wordwrap filter to split your text in lines with equal length.\n\n```\n{{ \"Lorem ipsum dolor sit amet, consectetur adipiscing\" | wordwrap(10) }}\n```\nThis example would print:\n\n```\nLorem ipsu  \nm dolor si  \nt amet, co  \nnsectetur  \nadipiscing  \n```\n\nThe default separator is \"\\n\", but you can easily change that by providing one:\n\n```\n{{ \"Lorem ipsum dolor sit amet, consectetur adipiscing\" | wordwrap(10, \"zz\\n\") }}\n```\n\nThis would result in:\n\n```\nLorem ipsuzz  \nm dolor sizz  \nt amet, cozz  \nnsectetur zz  \nadipiscing  \n```\n\n### strpad\n\nPad a string to a certain length with another string from both sides.\n\n```\n{{ 'xxx' | strpad(7, 'o') }}\n```\n\nThis would print:\n\n```\nooxxxoo\n```\n\n### str_replace\n\nReplace all occurrences of the search string with the replacement string.\n\n```\n{{ 'Alice' | str_replace('Alice', 'Bob') }}\n```\n\nThis would return:\n\n```\nBob\n```\n\n### strip_tags\n\nStrip HTML and PHP tags from a string. In first parameter you can specify allowable tags.\n\n```\n{{ '\u003cp\u003e\u003cb\u003eText\u003c/b\u003e\u003c/p\u003e' | strip_tags('\u003cp\u003e') }}\n```\n\nThis would return:\n\n```\n\u003cp\u003eText\u003c/p\u003e\n```\n\n### leftpad\n\nPad a string to a certain length with another string from left side.\n\n```\n{{ 'xxx' | leftpad(5, 'o') }}\n```\n\nThis would print:\n\n```\nooxxx\n```\n\n### rightpad\n\nPad a string to a certain length with another string from right side.\n\n```\n{{ 'xxx' | rightpad(5, 'o') }}\n```\n\nThis would print:\n\n```\nxxxoo\n```\n\n### rtl\n\nReverse a string.\n\n```\n{{ 'Hello world!' | rtl }}\n```\n\nThis would print:\n\n```\n!dlrow olleH\n```\n\n### shuffle\n\nShuffle an array.\n\n```\n{{ songs | shuffle }}\n```\n\nor in foreach:\n\n```\n{% for fruit in ['apple', 'banana', 'orange'] | shuffle %}\n\t{{ fruit }}\n{% endfor %}\n```\n\n### time_diff\n\nUse the time_diff filter to render the difference between a date and now.\n\n```\n{{ post.published_at | time_diff }}\n```\n\nThe example above will output a string like 4 seconds ago or in 1 month, depending on the filtered date.\n\nOutput is **translatable**. All translations are stored at `/lang` folder in this plugin. If you want more locales, just copy them from [this repository](https://github.com/KnpLabs/KnpTimeBundle/tree/master/Resources/translations), replace `%count%` with `:count` and send it as pull reqest to this repository.\n\n#### Arguments\n\n- date: The date for calculate the difference from now. Can be a string or a DateTime instance.\n- now: The date that should be used as now. Can be a string or a DateTime instance. Do not set this argument to use current date.\n\n#### Translation\n\nTo get a translatable output, give a Symfony\\Component\\Translation\\TranslatorInterface as constructor argument. The returned string is formatted as diff.ago.XXX or diff.in.XXX where XXX can be any valid unit: second, minute, hour, day, month, year.\n\n### localizeddate\n\nUse the localizeddate filter to format dates into a localized string representating the date. Note that **php5-intl extension**/**php7-intl extension** has to be installed!\n\n```\n{{ post.published_at | localizeddate('medium', 'none', locale) }}\n```\n\nThe localizeddate filter accepts strings (it must be in a format supported by the strtotime function), DateTime instances, or Unix timestamps.\n\n#### Arguments\n- date_format: The date format. Choose one of these formats:\n    - 'none': IntlDateFormatter::NONE\n    - 'short': IntlDateFormatter::SHORT\n    - 'medium': IntlDateFormatter::MEDIUM\n    - 'long': IntlDateFormatter::LONG\n    - 'full': IntlDateFormatter::FULL\n- time_format: The time format. Same formats possible as above.\n- locale: The locale used for the format. If NULL is given, Twig will use Locale::getDefault()\n- timezone: The date timezone\n- format: Optional pattern to use when formatting or parsing. Possible patterns are documented in the ICU user guide.\n\n### localizednumber\n\nUse the localizednumber filter to format numbers into a localized string representating the number. Note that **php5-intl extension** has to be installed!\n\n```\n{{ product.quantity | localizednumber }}\n```\n\nInternally, Twig uses the PHP NumberFormatter::create() function for the number.\n\n#### Arguments\n\n- style: Optional date format (default: 'decimal'). Choose one of these formats:\n    - 'decimal': NumberFormatter::DECIMAL\n    - 'currency': NumberFormatter::CURRENCY\n    - 'percent': NumberFormatter::PERCENT\n    - 'scientific': NumberFormatter::SCIENTIFIC\n    - 'spellout': NumberFormatter::SPELLOUT\n    - 'ordinal': NumberFormatter::ORDINAL\n    - 'duration': NumberFormatter::DURATION\n- type: Optional formatting type to use (default: 'default'). Choose one of these types:\n    - 'default': NumberFormatter::TYPE_DEFAULT\n    - 'int32': NumberFormatter::TYPE_INT32\n    - 'int64': NumberFormatter::TYPE_INT64\n    - 'double': NumberFormatter::TYPE_DOUBLE\n    - 'currency': NumberFormatter::TYPE_CURRENCY\n- locale: The locale used for the format. If NULL is given, Twig will use Locale::getDefault()\n\n### localizedcurrency\n\nUse the localizedcurrency filter to format a currency value into a localized string. Note that **php5-intl extension** has to be installed!\n\n```\n{{ product.price | localizedcurrency('EUR') }}\n```\n\n#### Arguments\n\n- currency: The 3-letter ISO 4217 currency code indicating the currency to use.\n- locale: The locale used for the format. If NULL is given, Twig will use Locale::getDefault()\n\n### mailto\n\nFilter for rendering email as normal mailto link, but with encryption against bots!\n\n```\n{{ 'vojtasvoboda.cz@gmail.com' | mailto }}\n```\n\nreturns\n\n```\n\u003cspan id=\"e846043876\"\u003e[javascript protected email address]\u003c/span\u003e\u003cscript type=\"text/javascript\"\u003e/*\u003c![CDATA[*/eval(\"var a=\\\"9IV1G0on6.ryWZYS28iPcNBwq4aeUJF5CskjuLQAh3XdlEz@7KtmpHbTxM-ODg_+Rvf\\\";var b=a.split(\\\"\\\").sort().join(\\\"\\\");var c=\\\"_TtD3O_TXTl3VdfZ@H3KpVdTH\\\";var d=\\\"\\\";for(var e=0;e\u003cc.length;e++)d+=b.charAt(a.indexOf(c.charAt(e)));document.getElementById(\\\"e846043876\\\").innerHTML=\\\"\u003ca href=\\\\\\\"mailto:\\\"+d+\\\"\\\\\\\"\u003e\\\"+d+\\\"\u003c/a\u003e\\\"\")/*]]\u003e*/\u003c/script\u003e\n```\n\nwhich will be rendered to page as normal\n\n```\n\u003ca href=\"mailto:vojtasvoboda.cz@gmail.com\"\u003evojtasvoboda.cz@gmail.com\u003c/a\u003e\n```\n\nPHP encrypts your email address and generates the JavaScript that decrypts it. Most bots can't execute JavaScript and that is what makes this work. A visitors of your web page will not notice that you used this script as long as they has JavaScript enabled. The visitors will see \"[javascript protected email address]\" instead of the email address if they has JavaScript disabled.\n\n#### Filter parameters\n\n```\n{{ 'vojtasvoboda.cz@gmail.com' | mailto(true, true, 'Let me know', 'my-class') }}\n```\n\n- first boolean parameter = returns email clickable (with link)\n- second boolean parameter = encryption is enabled\n- third string parameter = link text (not encrypted!)\n- fourth (optional) parameter = CSS class name (will render \u0026lt;a mailto:.. class=\"my-class\"\u0026gt;..) \n\n### var_dump\n\nDumps information about a variable.\n\n```\n\u003cpre\u003e{{ users | var_dump }}\u003c/pre\u003e\n```\n\n### revision\n \nForce the browser to reload cached modified/updated asset files.\nYou can provide a format parameter so that the prepended timestamp get converted accordingly to the PHP date() function.\n\n#### usage\n```\n\u003cimg src=\"{{ 'assets/images/image_file.jpg' | theme | revision(\"m.d.y.H.i.s\") }}\" alt=\"an image\" /\u003e\n```\n\nWill return something like\n```\n\u003cimg src=\"https://www.example.com/themes/my-theme/assets/image_file.png?12.03.16.04.52.38\" alt=\"An image\" /\u003e\n```\n\nSee: https://github.com/vojtasvoboda/oc-twigextensions-plugin/issues/25  \n\nhttps://stackoverflow.com/questions/32414/how-can-i-force-clients-to-refresh-javascript-files  \n\nhttp://php.net/manual/en/function.date.php  \n\n### sortbyfield\n\nSort array/collection by given field (key).\n\n```\n{% set data = [{'name': 'David', 'age': 31}, {'name': 'John', 'age': 28}] %}\n{% for item in data | sortbyfield('age') %}\n    {{ item.name }}\u0026nbsp;\n{% endfor %}\n```\n\nOutput will be: John David \n\n## Contributing\n\n- [ ] Fix time_diff unit test, which pass at local machine, but fails at TravisCI.\n- [ ] Convert PHP functions and custom code to the Twig_Extension classes.\n- [ ] Create Twig_Extension loader and load all extensions and filters as Twig_Extension automatically from config.\n- [ ] New filters *ga* and *gtm* for adding GA or GTM code (Heap Analytics) - {{ 'UA-1234567' | ga }}.\n- [ ] Add [cache extension](https://github.com/vojtasvoboda/oc-twigextensions-plugin/issues/11).\n\n**Feel free to send pullrequest!** Please, send Pull Request to master branch.\n\n## License\n\nTwig extensions plugin is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT) same as OctoberCMS platform.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreative-sizzle%2Fwn-twigextensions-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcreative-sizzle%2Fwn-twigextensions-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreative-sizzle%2Fwn-twigextensions-plugin/lists"}