{"id":19450866,"url":"https://github.com/morning-train/wp-blocks","last_synced_at":"2025-04-25T03:32:09.297Z","repository":{"id":62551362,"uuid":"509389266","full_name":"Morning-Train/wp-blocks","owner":"Morning-Train","description":"A package for working with WordPress Gutenberg blocks more easily.","archived":false,"fork":false,"pushed_at":"2023-09-11T09:31:51.000Z","size":80,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-20T10:24:55.773Z","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/Morning-Train.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":"2022-07-01T09:05:40.000Z","updated_at":"2023-01-13T13:27:52.000Z","dependencies_parsed_at":"2024-11-10T16:40:49.181Z","dependency_job_id":null,"html_url":"https://github.com/Morning-Train/wp-blocks","commit_stats":{"total_commits":36,"total_committers":2,"mean_commits":18.0,"dds":0.08333333333333337,"last_synced_commit":"fca673439170d31c114aad441c647634c4669575"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morning-Train%2Fwp-blocks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morning-Train%2Fwp-blocks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morning-Train%2Fwp-blocks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morning-Train%2Fwp-blocks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Morning-Train","download_url":"https://codeload.github.com/Morning-Train/wp-blocks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250748099,"owners_count":21480778,"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-11-10T16:39:19.690Z","updated_at":"2025-04-25T03:32:08.984Z","avatar_url":"https://github.com/Morning-Train.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Morningtrain\\WP\\Blocks\n\nA Morningtrain package for working with WordPress blocks more easily.\n\n## 📋 Table of Contents\n\n[[_TOC_]]\n\n## Introduction\n\nThis tool is made for organizing WordPress Gutenberg blocks!\n\nThis tool lets you:\n\n- Load all blocks found in a directory\n- Render Blade views by defining them as `renderView` in block meta\n- Load PHP dependencies by placing `*.php` files next to the `block.json` files\n\n## Getting Started\n\nTo get started install the package as described below in [Installation](#installation).\n\nTo use the tool have a look at [Usage](#usage)\n\n### Installation\n\nInstall with composer\n\n```bash\ncomposer require morningtrain/wp-blocks\n```\n\n## Dependencies\n\n### morningtrain/php-loader\n\n[PHP Loader](https://github.com/Morning-Train/php-loader) is used to load and initialize all Hooks\n\n## Usage\n\n### Loading the block directory\n\nTo initialize the package and/or to load blocks from a path use `Blocks::setup`\n\n```php\nuse Morningtrain\\WP\\Blocks\\Blocks;\n// Tell Blocks where the built/compiled files are located\nBlocks::setup(__DIR__ . \"/public/build/blocks\");\n\n// To add another directory\nBlocks::registerBlockDirectory(__DIR__ . \"/public/build/blocks\");\n```\n\n## Using a View\n\nTo serverside render a block using a Blade View set the custom `renderView` property.\n\nYou can also have custom PHP code dependency. By declaring `phpScript` the given script will be loaded alongside the\nregistration of your block.\nThis is especially useful when needing a View Composer.\n\nNote the custom schema url!\n\n```json\n{\n    \"$schema\": \"https://wp.cdn.mtra.in/default/schemas/block.json\",\n    \"apiVersion\": 3,\n    \"name\": \"foo/bar\",\n    \"version\": \"0.1.0\",\n    \"title\": \"Bar\",\n    \"textdomain\": \"foo\",\n    \"editorScript\": \"file:./index.js\",\n    \"editorStyle\": \"file:./index.css\",\n    \"style\": \"file:./style-index.css\",\n    \"renderView\": \"my-view\",\n    \"phpScript\": \"file:./script.php\",\n    \"viewPhpScript\": [\n        \"file:./view-script.php\",\n        \"file:./view-script2.php\"\n    ],\n    \"editorPhpScript\": \"file:./editor-script.php\"\n}\n```\n\nThe view will have the following vars: `$block`, `$attributes`, `$content` and `$blockProps`\n\nExample:\n\n```\n\u003cdiv {!! $blockProps !!}\u003e\n    \u003ch2\u003e{{$attributes['title']}}\u003c/h2\u003e\n    \u003cdiv\u003e{!! $content !!}\u003c/div\u003e\n\u003c/div\u003e\n```\n\nIf you wish to view compose you may create a `*.php` file within your block folder.\nAs long as it is a sibling to the `block.json` file and is not named `*.asset.php` then it will automatically be loaded.\n\n## Caching\n\nIf your environment is `production` then a cache containing all block files and their dependencies will be generated and\nused so that the server doesn't have to look for them on every request.\n\nTo clear this cache you can use the CLI command:\n\n```sh\nwp wp-blocks deleteCacheFiles\n```\n\n## Credits\n\n- [Mathias Munk](https://github.com/mrmoeg)\n- [All Contributors](../../contributors)\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorning-train%2Fwp-blocks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorning-train%2Fwp-blocks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorning-train%2Fwp-blocks/lists"}