{"id":23468183,"url":"https://github.com/wpup/digster","last_synced_at":"2025-09-02T16:51:39.991Z","repository":{"id":56982661,"uuid":"32102150","full_name":"wpup/digster","owner":"wpup","description":"Twig templates for WordPress","archived":false,"fork":false,"pushed_at":"2019-04-28T19:30:05.000Z","size":182,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T13:21:38.373Z","etag":null,"topics":["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/wpup.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":"2015-03-12T20:58:17.000Z","updated_at":"2023-08-24T15:01:16.000Z","dependencies_parsed_at":"2022-08-21T12:20:16.297Z","dependency_job_id":null,"html_url":"https://github.com/wpup/digster","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/wpup/digster","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wpup%2Fdigster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wpup%2Fdigster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wpup%2Fdigster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wpup%2Fdigster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wpup","download_url":"https://codeload.github.com/wpup/digster/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wpup%2Fdigster/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273317760,"owners_count":25084038,"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-09-02T02:00:09.530Z","response_time":77,"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":["twig","wordpress"],"created_at":"2024-12-24T13:19:41.833Z","updated_at":"2025-09-02T16:51:39.942Z","avatar_url":"https://github.com/wpup.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Digster\n\n[![Build Status](https://travis-ci.org/wpup/digster.svg?branch=master)](https://travis-ci.org/wpup/digster)\n[![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/)\n\n\u003e Twig templates for WordPress\n\nDigster it's a WordPress plugin that allows you to render Twig views with a\nfew Twig [filters](#twig-filters), [functions](#twig-functions) and [globals](#twig-globals).\n\nIt's easy to register your own [extensions](#register-extension) or [composers](#register-composer).\n\n## Install\n\n```\ncomposer require frozzare/digster\n```\n\n## Example\n\nExample of `page.php`\n\n```php\n/**\n * Render page view.\n */\necho view( 'page' );\n```\n\nExample of `page.twig`\n\n```jinja\n{% include \"partials/header.twig\" %}\n\u003cdiv id=\"primary\" class=\"content-area\"\u003e\n\t\u003cmain id=\"main\" class=\"site-main\" role=\"main\"\u003e\n\t\t\u003carticle class=\"post-2 page type-page status-publish hentry\"\u003e\n\t\t\t\u003cheader class=\"entry-header\"\u003e\n\t\t\t\t\u003ch1 class=\"entry-title\"\u003e{{ post.post_title }}\u003c/h1\u003e\n\t\t\t\u003c/header\u003e\n\t\t\t\u003cdiv class=\"entry-content\"\u003e\n\t\t\t\t{{ post.post_content | wpautop | raw }}\n\t\t\t\u003c/div\u003e\n\t\t\u003c/article\u003e\n\t\u003c/main\u003e\n\u003c/div\u003e\n{% include \"partials/footer.twig\" %}\n```\n\n## Configuration\n\nDigster has a few WordPress filters, one is the config filter. Debug is turn on by default if `WP_ENV` equals `development`\n\n```php\nadd_filter( 'digster/config', function ( $config ) {\n  return $config;\n} );\n```\n\n#### Locations\n\nA array with the locations of the views. By default\nthe `get_templates_directory() . '/views'` is registered.\n\n```php\nadd_filter( 'digster/config', function ( $config ) {\n  $config['locations'] = 'path/to/locations';\n  return $config;\n} );\n```\n\n#### Twig environment options\n\nRead about the options on the [Twig site](http://twig.sensiolabs.org/doc/api.html#environment-options)\n\n`auto_reload` example\n```php\nadd_filter( 'digster/config', function ( $config ) {\n  $config['auto_reload'] = true;\n  return $config;\n} );\n```\n\n## API functions\n\nAll functions that has `digster_` prefix can also be called as a static method on `\\Frozzare\\Digster\\Digster` class. Just replace `digster_` with `Digster::`, make sure that you have in your code `use Frozzare\\Digster\\Digster`\n\n##### Fetch view\n\nFetch the view in to a string.\n\n```php\n$view = digster_fetch( 'page' [, $data = [] ] );\n```\n\n#### Get the view instance\n\nEvery view in digster is a instance of the view class and this can be accessed.\n\n```php\n$view = digster_view( 'page', [, $data = [] ] );\n\n// or (only if `view` function don't exists.)\n$view = view( 'page', [, $data = [] ] );\n\necho $view;\n```\n\n#### Nested views\n\n`digster_view` or `view` will return the view instance so you can use the `nest` method.\n\n```php\necho view( 'user.profile' )\n  -\u003enest( 'picture', 'user.profile.picture', [\n    'url' =\u003e 'http://site.com/user/1/profile.png'\n  ] );\n```\n\n```jinja\n{# views/user/profile.twig #}\n{{ picture }}\n```\n\n```jinja\n{# views/user/profile/picture.twig #}\n\u003cimg src=\"{{ url }}\" alt=\"Profile picture\" /\u003e\n```\n\nYou can do the same with `digster_render` and `digster_fetch`\n\n```php\ndigster_render( 'user.profile', [\n  'picture' =\u003e digster_fetch( 'user.profile.picture', [\n      'url' =\u003e 'http://site.com/user/1/profile.png'\n  ] )\n] );\n```\n\n#### Register composer\n\nWith Digster you can register composer with wildcard template or a specified template.\n\nThis example is for `post` object, but Digster already have this global variable loaded.\n\n```php\n// '*', 'page' or 'page.twig'\ndigster_composer( 'page', function ( $vars ) {\n  $vars['post'] = is_numeric( $vars['post'] ) ?  get_page( $vars['post'] ) : $vars['post'];\n  return $vars;\n});\n\n// Only need to get the post ID\ndigster_render( 'page', [\n  'post' =\u003e get_the_ID()\n] );\n```\n\nYou can also create a composer class that you can add with `digster_composer`. The only method that is required on a composer class is `compose` that takes a view argument.\n\n```php\nclass Profile_Composer {\n\n  public function compose( $view ) {\n    $view-\u003ewith( 'job', 'developer' );\n  }\n\n}\n\ndigster_composer( 'user.profile', 'Profile_Composer' );\n```\n\n#### Register custom filters\n\nSince `1.7.1`\n\n```php\nadd_filter( 'digster/filters', function ( $filters ) {\n  return array_merge( $filters, [\n    'hello' =\u003e function ( $text ) {\n      return 'hello';\n    }\n  ] )\n} );\n```\n\n#### Register custom functions\n\nSince `1.7.1`\n\n```php\nadd_filter( 'digster/functions', function ( $functions ) {\n  return array_merge( $functions, [\n    'uniqid' =\u003e 'uniqid'\n  ] )\n} );\n```\n\n#### Register custom globals\n\nSince `1.7.1`\n\n```php\nadd_filter( 'digster/globals', function ( $globals ) {\n  return array_merge( $globals, [\n    'num' =\u003e 1\n  ] )\n} );\n```\n\n#### Register extension\n\nRegister [Twig extension](http://twig.sensiolabs.org/doc/advanced.html) classes with Digster.\n\n```php\ndigster_register_extensions( new My_First_Twig_Extension() );\n\n// or\n\ndigster_register_extensions( [\n\tnew My_First_Twig_Extension(),\n\tnew My_Second_Twig_Extension()\n] );\n```\n\n#### Render a view\n\nRender a view\n\n```php\ndigster_render( 'page' [, $data = []] );\n```\n\n#### Share data between views\n\nYou can either use `digster_composer` with `*` (wildcard) to share data between views or use `digster_share`. All shared that can be overwrite.\n\n```php\ndigster_share( 'site_name', 'Example' );\n```\n\n## Twig filters\n\n#### apply_filters\n\nApply filters to Twig output.\n\n```jinja\n{{ '@frozzare' | apply_filters('twitter_link') }}\n```\n\n#### Excerpt\n\nGet the post summary\n\n```jinja\n{{ post.post_content | excerpt }}\n```\n\n#### Shortcodes\n\nRun WordPress shortcodes on the text\n\n```jinja\n{{ post.post_content | shortcodes | raw }}\n```\n#### wpautop\n\nAppend p tags to the text\n\n```jinja\n{{ post.post_content | wpautop | raw }}\n```\n\n## Twig functions\n\nSince `1.7.1` you can call `esc_html__`, `esc_html_e`, `esc_attr__`, `esc_attr_e`, `esc_js`, `esc_textarea`, `esc_url` and `esc_url_raw` with the same arguments as you should use in WordPress.\n\n#### Call `__`\n\nThe same argument as WordPress's [__](https://codex.wordpress.org/Function_Reference/_2).\n\nDigster has full support for Twig i18n, [read more about it](#twig-i18n).\n\n```jinja\n{{ __( 'Hello World!', 'your_textdomain' ) }}\n```\n\n#### Call `_n`\n\nThe same argument as WordPress's [_n](https://codex.wordpress.org/Function_Reference/_n).\n\nDigster has full support for Twig i18n, [read more about it](#twig-i18n).\n\n```jinja\n{{ _n('%s star', '%s stars', rating, 'your_textdomain') | format(rating) }}\n```\n\n#### Call action\n\nYou can send more arguments to `do action`\n\n```jinja\n{% do action('my_action') %}\n```\n\n#### Call apply_filters\n\nTakes the same arguments as `apply_filters`\n\n```jinja\n{{ apply_filters() }}\n```\n\n#### Call body_class\n\n```jinja\n\u003cbody {{ body_class() }}\u003e\n```\n\n#### Call language_attributes\n\n```jinja\n\u003chtml {{ language_attributes() }}\u003e\n```\n\n#### Call random function\n\nYou can send in more arguments to `fn`\n\n```jinja\n\u003cbody {{ fn('my_function', 'a', 'b') }}\u003e\n```\n\n#### Call wp_footer\n\n```jinja\n{{ wp_footer() }}\n```\n\n#### Call wp_head\n\n```jinja\n{{ wp_head() }}\n```\n\n#### Call wp_title\n\nTakes the same arguments as `wp_title`\n\n```jinja\n{{ wp_title() }}\n```\n\n## Twig globals\n\n#### post\n\n`post` is global when `get_the_ID()` returns a id.\n\n```jinja\n\u003ch1\u003e{{ post.post_title }}\u003c/h1\u003e\n```\n\n## Twig i18n\n\nDigster has full support for Twig [i18n](http://twig.sensiolabs.org/doc/extensions/i18n.html) extensions. You don't have to do anything to enable it, just use it! It will load the theme text domain automatic. Don't forget to add it to your `style.css`.\n\nUsing [Poedit](https://poedit.net)? You should look at [Twig Gettext Extractor](https://github.com/umpirsky/Twig-Gettext-Extractor)! Digster will install Twig Gettext Extractor so you don't have to do it!\n\n```jinja\n{% trans \"Hello World!\" %}\n\n{% trans string_var %}\n\n{% trans %}\n    Hello World!\n{% endtrans %}\n```\n\n## Cache\n\nLook at [Twig cache extension](https://github.com/asm89/twig-cache-extension) (Digster installs the package so you don't have to install it). Digster has a build in cache provider that uses the [WordPress Object cache](http://codex.wordpress.org/Class_Reference/WP_Object_Cache).\n\n```php\nuse Frozzare\\Digster\\Cache\\WordPress_Cache_Adapter;\nuse Asm89\\Twig\\CacheExtension\\CacheStrategy\\LifetimeCacheStrategy;\nuse Asm89\\Twig\\CacheExtension\\Extension as CacheExtension;\n\n$cache_provider  = new WordPress_Cache_Adapter();\n$cache_strategy  = new LifetimeCacheStrategy($cache_provider);\n$cache_extension = new CacheExtension($cache_strategy);\n\ndigster_register_extensions( $cache_extension );\n```\n\n## Coding style\n\nYou can check if your contribution passes the styleguide by installing [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) and running the following in your project directory:\n\n```\nvendor/bin/phpcs -s --extensions=php --standard=phpcs.xml src/\n```\n\n## License\n\nMIT © [Fredrik Forsmo](https://github.com/frozzare)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwpup%2Fdigster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwpup%2Fdigster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwpup%2Fdigster/lists"}