{"id":33951995,"url":"https://github.com/eexit/twig-context-parser","last_synced_at":"2025-12-30T16:18:06.435Z","repository":{"id":10884915,"uuid":"13175002","full_name":"eexit/twig-context-parser","owner":"eexit","description":"Allows to return a Twig template static variables without actually rendering it.","archived":true,"fork":false,"pushed_at":"2013-09-28T16:22:42.000Z","size":112,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-14T00:42:18.906Z","etag":null,"topics":["php","twig","twig-context-parser","twig-extension"],"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/eexit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-09-28T15:04:53.000Z","updated_at":"2023-01-28T07:12:54.000Z","dependencies_parsed_at":"2022-08-29T19:30:40.706Z","dependency_job_id":null,"html_url":"https://github.com/eexit/twig-context-parser","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/eexit/twig-context-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eexit%2Ftwig-context-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eexit%2Ftwig-context-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eexit%2Ftwig-context-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eexit%2Ftwig-context-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eexit","download_url":"https://codeload.github.com/eexit/twig-context-parser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eexit%2Ftwig-context-parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27689356,"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-12-12T02:00:06.775Z","response_time":129,"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":["php","twig","twig-context-parser","twig-extension"],"created_at":"2025-12-12T19:18:16.127Z","updated_at":"2025-12-12T19:18:18.823Z","avatar_url":"https://github.com/eexit.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Twig Context Parser [![Build Status](https://travis-ci.org/eexit/twig-context-parser.png?branch=master)](https://travis-ci.org/eexit/twig-context-parser)\n\nThis small script uses the internal Twig tokenize/parser/compiler to obtain a template variable out of its rendering context.\n\nIf you are building a flat file Twig CMS based, it might be very useful to work using parsed flat file variable. There are many uses.\n\nThis parser basically return all your variables set in Twig using the block `set` as complex as it might be:\n\n```\n{% set foo = [\n    {\"bar\":\"baz\"},\n    \"bar\",\n    range(0, 12, 2),\n    [\"yux\", {\n        \"baz\":\"yea\",\n        \"bar\":\"foo\",\n        \"range\":range(0, 100)\n    }]\n] %}\n```\n\nWill output:\n\n```\narray(1) {\n  'foo' =\u003e\n  array(4) {\n    [0] =\u003e\n    array(1) {\n      'bar' =\u003e\n      string(3) \"baz\"\n    }\n    [1] =\u003e\n    string(3) \"bar\"\n    [2] =\u003e\n    array(7) {\n      [0] =\u003e\n      int(0)\n      [1] =\u003e\n      int(2)\n      ...\n      [6] =\u003e\n      int(12)\n    }\n    [3] =\u003e\n    array(2) {\n      [0] =\u003e\n      string(3) \"yux\"\n      [1] =\u003e\n      array(3) {\n        'baz' =\u003e\n        string(3) \"yea\"\n        'bar' =\u003e\n        string(3) \"foo\"\n        'range' =\u003e\n        array(101) {\n          [0] =\u003e\n          int(0)\n          [1] =\u003e\n          int(1)\n          ...\n          [99] =\u003e\n          int(99)\n          [100] =\u003e\n          int(100)\n        }\n      }\n    }\n  }\n}\n```\n\n\n## Installation\n\nSupposing you are using [composer](http://getcomposer.org), add to your `composer.json`:\n\n```json\n{\n    \"require\": {\n        \"eexit/twig-context-parser\": \"0.1.*\"\n    }\n}\n```\n\n## Usage\n\n```php\nuse Eexit\\Twig\\ContextParser\\ContextParser;\n\n$loader = new \\Twig_Loader_String();\n$twig = new \\Twig_Environment($loader);\n\n$template = $twig-\u003eparse($twig-\u003etokenize('{% set foo = \"bar\" %}{% set baz = \"yux\" %}'));\n\n$context = new ContextParser($twig);\n\nvar_dump($context-\u003eparse($template)-\u003egetContext());\n\n/*\narray(2) {\n    'foo' =\u003e\n    string(3) \"bar\"\n    'baz' =\u003e\n    string(3) \"yux\"\n}\n*/\n```\n\nThe `ContextParser::getParser()` will return the node context once. Once you called the method, calling it again will return nothing.\nThis allows to use the same `ContextParser` instance to parse several template in a row.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feexit%2Ftwig-context-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feexit%2Ftwig-context-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feexit%2Ftwig-context-parser/lists"}