{"id":13513344,"url":"https://github.com/EvanLovely/plugin-twig-namespaces","last_synced_at":"2025-03-31T01:32:19.570Z","repository":{"id":56979999,"uuid":"70632241","full_name":"EvanLovely/plugin-twig-namespaces","owner":"EvanLovely","description":"Pattern Lab plugin for registering new Twig Namespaces","archived":false,"fork":false,"pushed_at":"2017-11-10T23:21:47.000Z","size":11,"stargazers_count":8,"open_issues_count":3,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-18T00:38:10.234Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/EvanLovely.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":"2016-10-11T20:25:08.000Z","updated_at":"2021-02-25T07:44:46.000Z","dependencies_parsed_at":"2022-08-21T08:40:43.354Z","dependency_job_id":null,"html_url":"https://github.com/EvanLovely/plugin-twig-namespaces","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvanLovely%2Fplugin-twig-namespaces","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvanLovely%2Fplugin-twig-namespaces/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvanLovely%2Fplugin-twig-namespaces/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvanLovely%2Fplugin-twig-namespaces/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EvanLovely","download_url":"https://codeload.github.com/EvanLovely/plugin-twig-namespaces/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246403961,"owners_count":20771526,"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":[],"created_at":"2024-08-01T04:00:53.216Z","updated_at":"2025-03-31T01:32:19.244Z","avatar_url":"https://github.com/EvanLovely.png","language":"PHP","funding_links":[],"categories":["External tools"],"sub_categories":["Pattern Lab"],"readme":"[![Packagist](https://img.shields.io/packagist/v/evanlovely/plugin-twig-namespaces.svg)](https://packagist.org/packages/evanlovely/plugin-twig-namespaces) [![Gitter](https://img.shields.io/gitter/room/pattern-lab/php.svg)](https://gitter.im/pattern-lab/php)\n\n# Twig Namespaces Plugin for Pattern Lab\n\nThis adds namespaces to Twig in Pattern Lab. \n\n## Installation\n\nTo add this plugin to your project using [Composer](https://getcomposer.org/) type:\n\n    composer require evanlovely/plugin-twig-namespaces\n\nSee Packagist for [information on the latest release](https://packagist.org/packages/evanlovely/plugin-twig-namespaces).\n\n## Usage\n\nIn `config.yml`, add this:\n\n```yml\nplugins:\n  twigNamespaces:\n    enabled: true\n    roots: \n      - ../root1\n      - ../root2\n    namespaces:\n      foo:\n        recursive: true\n        paths:\n          - ../bar\n          - ../baz\n```\n\nPaths are relative to `composer.json` and `vendor/` in the same directory as the config directory (not config file). Assuming this folder structure\n\n- pattern-lab/\n  - config/\n    - config.yml\n  - composer.json\n- root1/\n  - 01-mountains/\n    - hood.twig\n  - 02-rivers\n    - sandy.twig\n- bar/\n    - item1.twig\n    - subdir/\n        - subitem1.twig\n- baz/\n    - item2.twig\n\nYou could now use this in Twig:\n\n```twig\n{% include \"@mountains/hood.twig\" %}\n{% include \"@rivers/sandy.twig\" %}\n{@ include \"@foo/item1.twig\" %}\n{@ include \"@foo/subitem1.twig\" %}\n{@ include \"@foo/item2.twig\" %}\n```\n\nYou can use either the `roots` or the `namespaces` approach without the other. The `roots` approach is how Pattern Lab registers the namespaces of all folders under `source/_patterns/` like `@atoms` and is therefore useful for including files from other Pattern Labs (watch out for namespace collisions - i.e. you can only have one `@atoms`). And the `namespaces` approach is how the Drupal [Component Libraries](https://www.drupal.org/project/components) module registers Twig namespaces, though it could also be used to register the core modules template files in Pattern Lab so you could `{% extend \"@blocks/block.html.twig\" %}` if you'd like. If using `namespaces` and you set `recursive: true`, then it will add all sub directories. \n\nAlso, you can set `twigNamespaces.readFromFile` to a path to a JSON or Yaml file and it will read those contents and use it in place of `twigNamespaces.namespaces`.\n\n## Disabling the Plugin\n\nTo disable the plugin you can either directly edit `./config/config.yml` or use the command line option:\n\n    php core/console --config --set plugins.twigNamespaces.enabled=false\n\n---\n\n**Happy Pattern Labbing!**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEvanLovely%2Fplugin-twig-namespaces","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FEvanLovely%2Fplugin-twig-namespaces","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEvanLovely%2Fplugin-twig-namespaces/lists"}