{"id":20406676,"url":"https://github.com/xwp/wp-vip-twig","last_synced_at":"2025-07-26T16:08:17.723Z","repository":{"id":24183071,"uuid":"27573925","full_name":"xwp/wp-vip-twig","owner":"xwp","description":"VIP Twig WordPress Plugin","archived":false,"fork":false,"pushed_at":"2017-03-16T16:33:34.000Z","size":101,"stargazers_count":20,"open_issues_count":2,"forks_count":4,"subscribers_count":67,"default_branch":"master","last_synced_at":"2025-07-10T03:53:23.612Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xwp.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-05T04:14:42.000Z","updated_at":"2024-09-03T17:33:48.000Z","dependencies_parsed_at":"2022-08-22T04:40:37.063Z","dependency_job_id":null,"html_url":"https://github.com/xwp/wp-vip-twig","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/xwp/wp-vip-twig","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xwp%2Fwp-vip-twig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xwp%2Fwp-vip-twig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xwp%2Fwp-vip-twig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xwp%2Fwp-vip-twig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xwp","download_url":"https://codeload.github.com/xwp/wp-vip-twig/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xwp%2Fwp-vip-twig/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267191034,"owners_count":24050318,"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","status":"online","status_checked_at":"2025-07-26T02:00:08.937Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-11-15T05:18:40.148Z","updated_at":"2025-07-26T16:08:17.702Z","avatar_url":"https://github.com/xwp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- DO NOT EDIT THIS FILE; it is auto-generated from readme.txt --\u003e\n# VIP Twig\n\nProposal to make Twig conform for use on WordPress.com VIP and other production environments where runtime compilation of templates is not allowed.\n\n**Contributors:** [westonruter](https://profiles.wordpress.org/westonruter), [xwp](https://profiles.wordpress.org/xwp), [newscorpau](https://profiles.wordpress.org/newscorpau)  \n**Tags:** [twig](https://wordpress.org/plugins/tags/twig), [templates](https://wordpress.org/plugins/tags/templates)  \n**Stable tag:** trunk (master)  \n**License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html)  \n\n[![Build Status](https://travis-ci.org/xwp/wp-vip-twig.svg?branch=master)](https://travis-ci.org/xwp/wp-vip-twig) \n\n## Description ##\n\nThis plugin is an attempt to force Twig to work in a production environment where\nruntime compilation of Twig templates into PHP class files is not allowed. This\nis true on WordPress.com VIP and should also be true on other production environments\nwhere filesystem write access is disabled (see also `DISALLOW_FILE_MODS`).\n\n**This plugin has not been approved by WordPress.com VIP for general use.**\n\nThis plugin does not currently provide any WordPress-specific extensions to Twig,\nsuch as those found in [Timber](http://upstatement.com/timber/); this plugin\ncould provide the Twig backend to Timber.\n\nThis plugin provides a global function `vip_twig_environment()` which can be used\nto access the plugin's instance of `Twig_Environment` which is available once\n`after_setup_theme` has fired. In other words, you can render a template via:\n\n```php\necho vip_twig_environment()-\u003erender( 'views/index.html.twig' ); // xss ok\n```\n\nThis plugin uses subclasses of `Twig_Environment` and `Twig_Loader_Filesystem`\nwhich have overridden methods to prevent any attempt to compile Twig templates\non the fly when on WordPress.com VIP or if `DISALLOW_FILE_MODS` is true and\n`WP_DEBUG` is not.\n\nWhen on a local dev environment where runtime compilation\nis allowed, the Twig templates will by default get written out to\na `{stylesheet_directory}/twig-cache`.\n\nThe cached PHP files compiled from Twig templates get corresponding names, as opposed\nto cache files being named with an opaque SHA256 hash.\nFor instance `components/common/primary-navigation.html.twig` gets compiled to\n`{cache_dir}/components/common/primary-navigation.html.twig.57ce91.php`.\nIn the same vein, this plugin overrides `Twig_Environment::getTemplateClass()`\nto generate PHP class names correspond the Twig template name used,\ne.g. `__TwigTemplate_components_common_primary_navigation_html_twig_57ce91`\n\nWhen wanting to do a deployment to production, this plugin provides a WP-CLI\ncommand `wp vip-twig compile` to walk over all Twig templates and compile them\ninto their corresponding PHP cache files at once so that they can be committed.\nAs such, a great `pre-commit` hook for a theme using this plugin would be:\n`wp vip-twig compile \u0026\u0026 git add -A twig-cache`\n\nBy default the Twig loader will look for templates in the child theme's\ndirectory (stylesheet directory), and the parent theme's directory\n(template directory). You may override this behavior or add more Twig template\npaths to search via the config filter, for instance within the context of a plugin:\n\n```php\nadd_filter( 'vip_twig_config', function ( $config ) {\n\tarray_unshift( $config['loader_template_paths'], plugin_dir_path( __FILE__ ) );\n\treturn $config;\n});\n```\n\nThis plugin also enforces that Twig templates only be loaded from the stylesheet\ndirectory, the template directory, the VIP shared plugins directory, or from an\norganization's specific plugins folder. This prevents including templates from\nother clients' codebases.\n\nIn the context of WordPress.com VIP, the intention is that the PHP files generated\nfrom Twig templates would get committed to SVN and code reviewed like any other\ncode being submitted to VIP.\n\nPHP 5.3+ is required.\n\n**Development of this plugin is done [on GitHub](https://github.com/xwp/wp-vip-twig).\nPull requests welcome. Please see any [issues](https://github.com/xwp/wp-vip-twig/issues) reported.**\n\n## Changelog ##\n\n### 0.1 ###\n* Initial release\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxwp%2Fwp-vip-twig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxwp%2Fwp-vip-twig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxwp%2Fwp-vip-twig/lists"}