{"id":16674282,"url":"https://github.com/wol-soft/twig-include-dir","last_synced_at":"2026-03-11T16:40:08.975Z","repository":{"id":57081599,"uuid":"146623444","full_name":"wol-soft/twig-include-dir","owner":"wol-soft","description":"Include all twig templates within a directory","archived":false,"fork":false,"pushed_at":"2024-11-25T09:26:35.000Z","size":28,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T22:12:18.424Z","etag":null,"topics":["directory","extension","include","php","php7","php8","recursive","template","twig"],"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/wol-soft.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-29T15:49:31.000Z","updated_at":"2024-11-25T09:26:38.000Z","dependencies_parsed_at":"2025-02-15T19:31:51.180Z","dependency_job_id":"6e0c701d-4bc8-40c3-bff7-c18bc8fdbbc9","html_url":"https://github.com/wol-soft/twig-include-dir","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/wol-soft%2Ftwig-include-dir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wol-soft%2Ftwig-include-dir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wol-soft%2Ftwig-include-dir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wol-soft%2Ftwig-include-dir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wol-soft","download_url":"https://codeload.github.com/wol-soft/twig-include-dir/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248104102,"owners_count":21048282,"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":["directory","extension","include","php","php7","php8","recursive","template","twig"],"created_at":"2024-10-12T12:30:04.722Z","updated_at":"2026-03-11T16:40:08.945Z","avatar_url":"https://github.com/wol-soft.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Version](https://img.shields.io/packagist/v/wol-soft/twig-include-dir.svg)](https://packagist.org/packages/wol-soft/twig-include-dir)\n[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.2-8892BF.svg)](https://php.net/)\n[![Build Status](https://github.com/wol-soft/twig-include-dir/actions/workflows/main.yml/badge.svg)](https://github.com/wol-soft/twig-include-dir/actions/workflows/main.yml)\n[![Coverage Status](https://coveralls.io/repos/github/wol-soft/twig-include-dir/badge.svg?branch=master)](https://coveralls.io/github/wol-soft/twig-include-dir?branch=master)\n[![MIT License](https://img.shields.io/packagist/l/wol-soft/twig-include-dir.svg)](https://github.com/wol-soft/twig-include-dir/blob/master/LICENSE)\n\n# twig-include-dir\nInclude all twig templates within a directory\n\n## Features ##\n\n- Provide a directory with multiple .twig templates and all templates will be included\n- Add *recursive* keyword to include all templates within a directory recursive\n- known variable handling as known from *include* using the keywords *only* and *with*\n\n## Requirements ##\n\n- Requires Twig \u003e= 2.7\n- Requires PHP \u003e= 7.2\n\n## Installation ##\n\nThe recommended way to install twig-include-dir is through [Composer](http://getcomposer.org):\n```\n$ composer require wol-soft/twig-include-dir\n```\n\n## Why? ##\n\nAn example use case could be: you set up a site using bootstrap with many modals. Now you don't need to throw all your modals together in a file or include each modal manually but instead you can separate your modals by using one file for each modal. Throw all modals in a modal-directory and simply include the whole directory. Adding a new modal? No problem, just create a new template file in your modal-directory.\n\n## Getting started ##\n\nTo use twig-include-dir you need to add the include-dir token parser to your Twig Environment first:\n\n```php\n\u003c?php\n\n/* ... */\n\n$loader = new FilesystemLoader(__DIR__ . DIRECTORY_SEPARATOR);\n$twig = new Environment($loader);\n$twig-\u003eaddTokenParser(new \\TwigIncludeDir\\IncludeDirTokenParser());\n\n/* ... */\n```\n\nAfterwards you can start using the added token *includeDir* in your templates:\n\n```twig\n\u003cdiv class=\"modal-container\"\u003e\n    {% includeDir '/modals' %}\n\u003c/div\u003e\n```\n\nThe files in the directory will be included alphabetically.\n\n### Recursive usage\n\nTo include all files within a given directory recursive simply add the keyword *recursive* to your include statement:\n\n```twig\n\u003cdiv class=\"modal-container\"\u003e\n    {% includeDir '/modals' recursive %}\n\u003c/div\u003e\n```\n\nNow also the modals from the directories */modals/user* and */modals/system* etc. will be included.\n\n__Caution:__ The templates will be included alphabetically as well, including the directories. Thus the template */modals/footer.twig* will be included before the templates from the directory */modals/system* followed by */modals/user* followed by a possible */modals/zebraHeader.twig*. It is recommended to use twig-include-dir only for templates which do __not__ require a specific order.\n\n### Variables\n\nAs known from the Twig Core *include* you can control the available variables with the keywords *with* and *only* (compare: [include](https://twig.symfony.com/doc/2.x/tags/include.html))\n\n```twig\n\u003cdiv class=\"modal-container\"\u003e\n    {# only the foo variable will be accessible #}\n    {% includeDir '/modals' recursive with {'foo': 'bar'} only %}\n\u003c/div\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwol-soft%2Ftwig-include-dir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwol-soft%2Ftwig-include-dir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwol-soft%2Ftwig-include-dir/lists"}