{"id":25428249,"url":"https://github.com/aaronkirkham/wp-timber-view-controller","last_synced_at":"2026-05-01T04:39:05.478Z","repository":{"id":56939076,"uuid":"129956383","full_name":"aaronkirkham/wp-timber-view-controller","owner":"aaronkirkham","description":"A view controller for using Timber on WordPress.","archived":false,"fork":false,"pushed_at":"2018-05-19T00:07:54.000Z","size":9,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-06T22:44:18.941Z","etag":null,"topics":["timber","timber-library","twig","wordpress"],"latest_commit_sha":null,"homepage":"","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/aaronkirkham.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-04-17T19:43:59.000Z","updated_at":"2018-12-10T22:36:29.000Z","dependencies_parsed_at":"2022-08-21T06:50:18.113Z","dependency_job_id":null,"html_url":"https://github.com/aaronkirkham/wp-timber-view-controller","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronkirkham%2Fwp-timber-view-controller","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronkirkham%2Fwp-timber-view-controller/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronkirkham%2Fwp-timber-view-controller/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronkirkham%2Fwp-timber-view-controller/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aaronkirkham","download_url":"https://codeload.github.com/aaronkirkham/wp-timber-view-controller/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239221263,"owners_count":19602378,"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":["timber","timber-library","twig","wordpress"],"created_at":"2025-02-17T01:38:22.874Z","updated_at":"2026-05-01T04:39:00.436Z","avatar_url":"https://github.com/aaronkirkham.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## WordPress Timber View Controller\nIf you're like me and hate writing 2 files to render a twig template for WordPress (e.g. page.php for context and page.twig for markup) then this library is for you. It follows the WordPress Template Hierarchy so you can also create files such as `single-{post_type}.twig`.\n\n### How to use\nUsing wp-timber-view-controller is easy.\n\n`composer require aaronkirkham/wp-timber-view-controller`\n\nThen place the following code inside your themes functions.php:\n\n```php\nrequire_once( __DIR__ . '/vendor/autoload.php' );\n\nnew Timber\\Timber;\nnew Timber\\ViewController;\n```\n\nand that's it. Your Twig templates will be automatically rendered.\n\nThis library uses the internal `Timber::$dirname` variable to locate your templates (default folder is `views`). If you want your files to live in a different folder, you must overwrite this.\n\n```php\n// look inside /templates/ instead of /views/\nTimber::$dirname = 'templates';\n```\n\nIf you need to add variables to the Timber context, there are handy filters available for that.\n\n### Filter: timber_context--%TEMPLATE%\nThe `timber_context--%TEMPLATE%` filter (where %TEMPLATE% is the current template name) is fired when the specific template is rendered. This is handy if you want to get posts from WordPress on specific pages.\n\n```php\nadd_filter( 'timber_context--404', function( $ctx ) {\n  $ctx['message'] = '404 - Not Found';\n  return $ctx;\n});\n```\n\n```php\nadd_filter( 'timber_context--single', function( $ctx ) {\n  $ctx['post'] = new \\Timber\\Post();\n  return $ctx;\n});\n```\n\nIn the above examples, the **message** variable will be available on all pages which are rendered using the 404.twig template, and the **post** variable will be available on all single.twig templates.\n\n### FYI\nIf you want to add data into the context for every template, you should use the `timber_context` filter which is fired by Timber.\n\n```php\nadd_filter( 'timber_context', function( $ctx ) {\n  $ctx['foo'] = 'bar';\n  return $ctx;\n});\n```\n\nThe variable **foo** is now available on all templates.\n\n### White screen?\n\nIf your twig templates are not rendered or you just have a white screen, you should turn on WP_DEBUG inside wp-config.php to view a hierarchical list of templates that wp-timber-view-controller tried to render. Double check the displayed template path and file names are correct.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronkirkham%2Fwp-timber-view-controller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faaronkirkham%2Fwp-timber-view-controller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronkirkham%2Fwp-timber-view-controller/lists"}