{"id":18309805,"url":"https://github.com/phpdevcommunity/template-bridge","last_synced_at":"2025-04-12T17:34:24.459Z","repository":{"id":257815076,"uuid":"869436931","full_name":"phpdevcommunity/template-bridge","owner":"phpdevcommunity","description":"TemplateBridge is a lightweight and versatile template rendering library that supports native PHP rendering and a custom C engine via a .so file for enhanced performance.","archived":false,"fork":false,"pushed_at":"2024-10-08T09:46:59.000Z","size":4,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-09T22:44:29.363Z","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/phpdevcommunity.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":"2024-10-08T09:44:06.000Z","updated_at":"2025-01-01T13:26:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"f7d1c432-f982-4579-af86-f092ea272d05","html_url":"https://github.com/phpdevcommunity/template-bridge","commit_stats":null,"previous_names":["phpdevcommunity/template-bridge"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpdevcommunity%2Ftemplate-bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpdevcommunity%2Ftemplate-bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpdevcommunity%2Ftemplate-bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpdevcommunity%2Ftemplate-bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phpdevcommunity","download_url":"https://codeload.github.com/phpdevcommunity/template-bridge/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248605613,"owners_count":21132201,"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-05T16:12:27.930Z","updated_at":"2025-04-12T17:34:24.433Z","avatar_url":"https://github.com/phpdevcommunity.png","language":"PHP","readme":"# PHP TemplateBridge\r\n\r\nTemplateBridge is a lightweight and versatile template rendering library that supports native PHP rendering and a custom C engine via a `.so` file for enhanced performance.\r\n\r\n## Installation\r\n\r\nYou can install the PHP Renderer library using Composer. Just run the following command:\r\n\r\n```bash\r\ncomposer require phpdevcommunity/template-bridge\r\n```\r\n\r\n## 1. Basic Usage of *PHP Renderer*\r\n\r\nTo use the PHP Renderer in your project, first create an instance of the `PhpRenderer` class and pass the directory where your templates are located:\r\n\r\n```php\r\nuse PhpDevCommunity\\TemplateBridge\\Renderer\\PhpRenderer;\r\n\r\n// Specify the template directory\r\n$templateDir = '/path/to/templates';\r\n\r\n// Optional parameters to be passed to the templates\r\n$parameters = [\r\n    'siteTitle' =\u003e 'My Website',\r\n];\r\n\r\n// Create the renderer instance\r\n$renderer = new PhpRenderer($templateDir, $parameters);\r\n```\r\n\r\n### Creating Templates\r\n\r\nCreate your templates using PHP files. For example, create a template file named `template.php` with the following content:\r\n\r\n```php\r\n\u003c?php $this-\u003eextend('layout.php'); ?\u003e\r\n\r\n\u003c?php $this-\u003estartBlock('title'); ?\u003e\r\n    My Page Title\r\n\u003c?php $this-\u003eendBlock(); ?\u003e\r\n\r\n\u003c?php $this-\u003estartBlock('content'); ?\u003e\r\n    \u003ch1\u003eHello, \u003c?php echo $name; ?\u003e!\u003c/h1\u003e\r\n    \u003cp\u003eWelcome to my website.\u003c/p\u003e\r\n\u003c?php $this-\u003eendBlock(); ?\u003e\r\n```\r\n\r\n### Creating Layouts\r\n\r\nCreate a layout file (e.g., `layout.php`) that represents the common structure of your web pages. Use blocks to define sections that will be replaced by content from individual templates.\r\n\r\n```php\r\n\u003c!DOCTYPE html\u003e\r\n\u003chtml\u003e\r\n\u003chead\u003e\r\n    \u003ctitle\u003e\u003c?php echo $this-\u003eblock('title'); ?\u003e\u003c/title\u003e\r\n\u003c/head\u003e\r\n\u003cbody\u003e\r\n    \u003cdiv class=\"container\"\u003e\r\n        \u003c?php echo $this-\u003eblock('content'); ?\u003e\r\n    \u003c/div\u003e\r\n\u003c/body\u003e\r\n\u003c/html\u003e\r\n```\r\n\r\n### Rendering Templates\r\n\r\nTo render your templates, use the `render` method of the `PhpRenderer` class:\r\n\r\n```php\r\necho $renderer-\u003erender('template.php', ['name' =\u003e 'John']);\r\n```\r\n\r\nThis will render the `template.php` with the provided context data and inject it into the `layout.php` to create the final HTML output.\r\n\r\n### Helper Methods\r\n\r\nYou can use the `get` method to access parameters passed to the renderer:\r\n\r\n```php\r\n// Get a parameter value\r\n$siteTitle = $this-\u003eget('siteTitle');\r\n```\r\n\r\n## 2. Basic Usage of *Go Renderer*\r\n\r\nNote: This feature is currently in development.\r\n\r\n## Contributing\r\n\r\nContributions to the TemplateBridge library are welcome! If you find any issues or want to suggest enhancements, feel free to open a GitHub issue or submit a pull request.\r\n\r\n## License\r\n\r\nTemplateBridge is open-source software released under the MIT License. See the [LICENSE](LICENSE) file for more details.\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpdevcommunity%2Ftemplate-bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpdevcommunity%2Ftemplate-bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpdevcommunity%2Ftemplate-bridge/lists"}