{"id":21013829,"url":"https://github.com/jdecool/twigconstantaccessorbundle","last_synced_at":"2025-05-15T04:34:37.007Z","repository":{"id":4093338,"uuid":"51859549","full_name":"jdecool/TwigConstantAccessorBundle","owner":"jdecool","description":"Simplify access of your class constants in Twig","archived":false,"fork":false,"pushed_at":"2024-11-23T13:44:21.000Z","size":145,"stargazers_count":9,"open_issues_count":3,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-13T17:09:32.599Z","etag":null,"topics":["constant","hacktoberfest","symfony-bundle","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/jdecool.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":"2016-02-16T18:46:29.000Z","updated_at":"2024-12-18T12:27:39.000Z","dependencies_parsed_at":"2024-04-18T20:33:03.386Z","dependency_job_id":"58ae51e3-9b3e-4790-8a98-51966c9bc427","html_url":"https://github.com/jdecool/TwigConstantAccessorBundle","commit_stats":{"total_commits":81,"total_committers":4,"mean_commits":20.25,"dds":0.09876543209876543,"last_synced_commit":"964dc03e4b1eca95888e328cc4fe21c75de615d5"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdecool%2FTwigConstantAccessorBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdecool%2FTwigConstantAccessorBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdecool%2FTwigConstantAccessorBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdecool%2FTwigConstantAccessorBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jdecool","download_url":"https://codeload.github.com/jdecool/TwigConstantAccessorBundle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254274690,"owners_count":22043568,"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":["constant","hacktoberfest","symfony-bundle","twig"],"created_at":"2024-11-19T09:44:17.079Z","updated_at":"2025-05-15T04:34:37.001Z","avatar_url":"https://github.com/jdecool.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TwigConstantAccessorBundle\n\n[![Build Status](https://github.com/jdecool/TwigConstantAccessorBundle/actions/workflows/ci.yml/badge.svg)](https://actions-badge.atrox.dev/jdecool/TwigConstantAccessorBundle/goto?ref=main)\n[![Latest Stable Version](https://poser.pugx.org/jdecool/twig-constant-accessor-bundle/v/stable.png)](https://packagist.org/packages/jdecool/twig-constant-accessor-bundle)\n\nThis bundle simplify access of your enum values or class constants in Twig.\n\n## Install it\n\nInstall extension using [composer](https://getcomposer.org):\n\n```bash\ncomposer require jdecool/twig-constant-accessor-bundle\n```\n\nIf you don't use Symfony Flex, you have to enabled the bundle in your `config/bundles.php` configuration:\n\n```php\n\u003c?php\n\nreturn [\n    // ...\n    JDecool\\Bundle\\TwigConstantAccessorBundle\\JDecoolTwigConstantAccessorBundle::class =\u003e ['all' =\u003e true],\n];\n```\n\nRegister the class you want to access constant in your configuration file :\n\n```yaml\ntwig_constant_accessor:\n    classes:\n        - AppBundle\\Model\\Foo\n        - { class: 'AppBundle\\Model\\Bar' }\n        - { class: 'AppBundle\\Model\\FooBar', alias: 'FooBarAlias' }\n        - { class: 'AppBundle\\Model\\ConstantClass', matches: '/^RULE_/' } # matches accept an regexp compatible with the preg_match function\n```\n\nYou can also register a class in your container configuration using the `twig.constant_accessor` tag :\n\n```yaml\nservices:\n    my_service:\n        class: Namespace\\To\\ServiceClass\n        tags:\n            - { name: twig.constant_accessor }\n\n    my_collection:\n        class: MyClass\n        tags:\n            - { name: twig.constant_accessor, alias: 'MyClassAlias' }\n\n    filtered_constants:\n        class: ConstantsClass\n        tags:\n            - { name: twig.constant_accessor, matches: '/^RULE_/' } # matches accept an regexp compatible with the preg_match function\n```\n\nOr you can use the `#[AsTwigConstantAccessor]` attribute on your class :\n\n```php\nuse JDecool\\Bundle\\TwigConstantAccessorBundle\\Annotation\\AsTwigConstantAccessor;\n\n#[AsTwigConstantAccessor]\nclass MyClass\n{\n    // ...\n}\n```\n\nAfter you can access your class constant in your templates :\n\n```twig\n{{ ServiceClass.MY_CONSTANT }}\n{{ MyClassAlias.KEY }}\n\n{% if 'value' == ServiceClass.My_CONSTANT %}Test is OK{% endif %}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdecool%2Ftwigconstantaccessorbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjdecool%2Ftwigconstantaccessorbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdecool%2Ftwigconstantaccessorbundle/lists"}