{"id":23631159,"url":"https://github.com/philecms/filterbykey","last_synced_at":"2025-10-09T00:16:09.398Z","repository":{"id":74330390,"uuid":"58159768","full_name":"PhileCMS/filterByKey","owner":"PhileCMS","description":"A plugin for Phile that adds a Twig function to filter a Page by a specific meta key","archived":false,"fork":false,"pushed_at":"2016-05-05T20:49:35.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-18T23:09:48.805Z","etag":null,"topics":["philecms-plugin"],"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/PhileCMS.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,"zenodo":null}},"created_at":"2016-05-05T20:49:17.000Z","updated_at":"2021-07-19T14:25:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"2fa76b62-ff46-4547-9d34-8aad0def33ae","html_url":"https://github.com/PhileCMS/filterByKey","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/PhileCMS/filterByKey","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhileCMS%2FfilterByKey","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhileCMS%2FfilterByKey/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhileCMS%2FfilterByKey/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhileCMS%2FfilterByKey/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PhileCMS","download_url":"https://codeload.github.com/PhileCMS/filterByKey/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhileCMS%2FfilterByKey/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265508240,"owners_count":23779102,"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":["philecms-plugin"],"created_at":"2024-12-28T02:48:55.892Z","updated_at":"2025-10-09T00:16:04.363Z","avatar_url":"https://github.com/PhileCMS.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"filterByKey\n===========\n\nA plugin for Phile that adds a Twig function to filter a Page by a specific meta key\n\n### 1.1 Installation (composer)\n\n```\nphp composer.phar require phile/filterByKey:*\n```\n\n### 1.2 Installation (Download)\n\n* Install [Phile](https://github.com/PhileCMS/Phile)\n* Clone this repo into `plugins/phile/filterByKey`\n\n### 2. Activation\n\nAfter you have installed the plugin. You need to add the following line to your `config.php` file:\n\n* add `$config['plugins']['phile\\\\filterByKey'] = array('active' =\u003e true);` to your `config.php`\n\n### What Is This For?\n\nI had a list of pages that only contained a *specific meta key* I wanted to iterate over. I also had to echo out a divider for each 3 items. I was going to use the [batch](http://twig.sensiolabs.org/doc/filters/batch.html) feature in Twig, but it required that my array was already sorted. So I needed a way to create a new array with only the pages that contained that specific meta key *and then* use batch on that new array.\n\nThis new Twig function allows you to filter an array of pages, into a new array of pages that only contains the meta key that you want. See the example below to see a real world use case.\n\n#### Examples:\n\n```twig\n{# Give me a new array, but leave out pages that dont have meta.instructor_name #}\n{% set team = filter_by_key(pages, 'instructor_name') %}\n\n\u003cdiv class=\"row\"\u003e\n{% for member in team %}\n  \u003cdiv class=\"col col-3\"\u003e\n    \u003ca href=\"{{ member.url }}\" title=\"{{ member.title }}\"\u003e{{ member.meta.instructor_name }}\u003c/a\u003e\n  \u003c/div\u003e\n{% endfor %}\n\u003c/div\u003e\n```\n\n```twig\n{# I only want an array that contains pages with 'Alt Data:' in the meta comment #}\n{% set items = filter_by_key(pages, 'alt_data') %}\n\n\u003ctable\u003e\n{% for row in items|batch(3, 'No item') %}\n    \u003ctr\u003e\n        {% for column in row %}\n            \u003ctd\u003e{{ column }}\u003c/td\u003e\n        {% endfor %}\n    \u003c/tr\u003e\n{% endfor %}\n\u003c/table\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphilecms%2Ffilterbykey","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphilecms%2Ffilterbykey","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphilecms%2Ffilterbykey/lists"}