{"id":15022109,"url":"https://github.com/widoz/twig-wordpress","last_synced_at":"2025-04-12T06:12:55.745Z","repository":{"id":57073946,"uuid":"122758345","full_name":"widoz/twig-wordpress","owner":"widoz","description":"The famous Twig Template for WordPress","archived":false,"fork":false,"pushed_at":"2018-12-15T14:49:06.000Z","size":60,"stargazers_count":5,"open_issues_count":8,"forks_count":0,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-04-12T06:12:48.369Z","etag":null,"topics":["template","template-engine","twig","unit-tested","wordpress"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/widoz.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":"2018-02-24T16:36:46.000Z","updated_at":"2024-09-12T20:30:47.000Z","dependencies_parsed_at":"2022-08-24T10:50:15.507Z","dependency_job_id":null,"html_url":"https://github.com/widoz/twig-wordpress","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/widoz%2Ftwig-wordpress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/widoz%2Ftwig-wordpress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/widoz%2Ftwig-wordpress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/widoz%2Ftwig-wordpress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/widoz","download_url":"https://codeload.github.com/widoz/twig-wordpress/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248525138,"owners_count":21118619,"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":["template","template-engine","twig","unit-tested","wordpress"],"created_at":"2024-09-24T19:57:28.234Z","updated_at":"2025-04-12T06:12:55.715Z","avatar_url":"https://github.com/widoz.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://img.shields.io/travis/widoz/twig-wordpress/develop.svg?style=flat-square)](https://travis-ci.org/widoz/twig-wordpress)\n[![codecov](https://img.shields.io/codecov/c/github/widoz/twig-wordpress/develop.svg?style=flat-square)](https://codecov.io/gh/widoz/twig-wordpress)\n[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/widoz/twig-wordpress/develop.svg?style=flat-square)](https://scrutinizer-ci.com/g/widoz/twig-wordpress/?branch=develop)\n\n# Twig for WordPress\n\nTwig for WordPress allow you to use the famous Twig template engine https://twig.symfony.com/\nbut extend it to be able to use the functions provided by WordPress such as `esc_html`, `esc_html__`, `wp_kses` etc...\n\nThis package register the escape function as filters and functions because translator functions need to be pass a textdomain.\n\n## Modules\n\nThe package provide filters, functions and other stuffs into twig by define `modules`.\n\nModules are class instances that implements an interface `TwigWp\\Module\\Injectable` used by\nthe Provider `TwigWp\\Module\\Provider` that allow us to retrieve all modules to be set into `twig` instance.\n\nThere is a filter `twigwp.modules` within the `Provider::modules` method that allow\nthird party softwares to hook into the modules list so, they'll be able to add other filters, functions, tags\nor whatever they want to use to extend the twig instance\n(read about how to extend twig here [https://twig.symfony.com/doc/2.x/advanced.html](https://twig.symfony.com/doc/2.x/advanced.html)).\n\n### Escapers\n\nTwig for WordPress define as filters and functions the followings:\n\n- esc_js\n- esc_sql\n- esc_textarea\n- esc_url\n- esc_url_raw\n- esc_attr\n- esc_html\n\n### Kses\n\nThe kses are defined only as functions.\n\n- wp_kses\n- wp_kses_post\n- wp_kses_allowed_html\n\n### Sanitizers\n\nThe sanitizers are defined only as functions.\n\n- sanitize_html_class\n- sanitize_text_field\n- sanitize_title\n- sanitize_key\n\n### L10n\n\nLocalization functions, including the escaped ones.\nLocalizations functions that start with `esc_` (escape) are also registered as filters.\n\n- __\n- _e\n- _n\n- _x\n- _ex\n- _nx\n- esc_attr__\n- esc_attr_e\n- esc_attr_x\n- esc_html__\n- esc_html_e\n- esc_html_x\n\n### Template Functions\n\nThis module include all of the functions that echo html markup even if\nthem are not WordPress template functions.\n\nThis because most of the WordPress functions usually get some configuration by array and output html markup.\nHaving to put in a object property the entire markup isn't usefull since you want to have your markup\ninto your views, these functions will help you to pass the configuration and call the output function\ndirectly, avoiding to permit to parse html markup that may result in a unescaped html.\n\n- wp_nav_menu\n- get_adjacent_post_link\n\n## Provider\n\nThe modules are retrieved by a Provider.\n\nWithin the provider the modules can be filtered `twigwp.modules`.\n\nSo if you want to add a new module you can hook into this filter and return a new instance of `TwigWp\\Module\\Injectable`.\n\nA Module is used to extend the twig instance, the method `injectInto` get a `\\Twig\\Environment` instance to use for example\nto add a new function, a new filter or a new tag etc...\n\nFor example:\n\n```php\nclass MyModule implements TwigWp\\Module\\Injectable {\n\n\tpublic function injectInto(\\Twig\\Environment $twig): \\Twig\\Environment {\n\t\t// Do your stuffs here.\n\n\t\treturn $twig;\n\t}\n\n}\n\n$provider = new Provider(new \\Twig\\Environmnet());\n\nadd_filter('twigwp.modules', function($modules)\n{\n\t$modules['module_name'] = new MyModule();\n\n\treturn $modules;\n});\n\n$modules = $provider-\u003emodules();\n```\n\nThis is just an example because you'll never need to create an instance of the Module `Provider`.\nEverything is handled by the `Factory` class.\n\nYou just need to add your filter and everything is ok.\n\n## Factory\n\nThe package provide a `Factory` class that help you on creating a new instance of the `\\Twig\\Environment` class.\n\nIf you want to create a new Twig instance you can simply create a factory instance by passing\na `\\Twig\\Loader\\LoaderInterface` object and the twig options if you want to customize the environment.\n\nThen call the `create` method and you've done.\n\n```php\n$twigFactory = new \\TwigWp\\Factory(\n\tnew \\Twig\\Loader\\FilesystemLoader(),\n\t[\n        'debug' =\u003e false,\n        'charset' =\u003e 'UTF-8',\n        'base_template_class' =\u003e 'Twig_Template',\n        'strict_variables' =\u003e false,\n        'autoescape' =\u003e 'html',\n        'cache' =\u003e false,\n        'auto_reload' =\u003e null,\n        'optimizations' =\u003e -1,\n\t]\n);\n\n$twig = $twigFactory-\u003ecreate();\n```\n\nPretty easy, right?\n\n## License\nThis programm is free software and is licensed using GPL2.\n\nFor more info about the license see [https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html)\n\n## Requirements\n\nPHP \u003e= 7.0\n\n## Bugs Reporting\n\nTo report bugs please refer to [https://github.com/widoz/twig-wordpress/issues](https://github.com/widoz/twig-wordpress/issues)\n\n## Support\n\nFor support just open a new issue [https://github.com/widoz/twig-wordpress/issues](https://github.com/widoz/twig-wordpress/issues) and apply the label `help wanted`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwidoz%2Ftwig-wordpress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwidoz%2Ftwig-wordpress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwidoz%2Ftwig-wordpress/lists"}