{"id":15041838,"url":"https://github.com/codespede/yii2-template-renderer","last_synced_at":"2026-01-02T01:24:26.727Z","repository":{"id":56955754,"uuid":"151272190","full_name":"codespede/yii2-template-renderer","owner":"codespede","description":"Facility for rendering data in any custom format/structure with just a parent-view, child-view and DataProvider(Supports pagination, sorting, filtering and all other operations supported by DataProvider).","archived":false,"fork":false,"pushed_at":"2018-10-20T17:23:12.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-20T18:33:23.513Z","etag":null,"topics":[],"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/codespede.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}},"created_at":"2018-10-02T14:51:02.000Z","updated_at":"2018-10-20T17:23:14.000Z","dependencies_parsed_at":"2022-08-21T08:50:39.428Z","dependency_job_id":null,"html_url":"https://github.com/codespede/yii2-template-renderer","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codespede%2Fyii2-template-renderer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codespede%2Fyii2-template-renderer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codespede%2Fyii2-template-renderer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codespede%2Fyii2-template-renderer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codespede","download_url":"https://codeload.github.com/codespede/yii2-template-renderer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243495495,"owners_count":20299923,"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-09-24T20:46:32.156Z","updated_at":"2026-01-02T01:24:26.683Z","avatar_url":"https://github.com/codespede.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Template Renderer for Yii 2\n===========================\n\nFacilitates rendering data in any custom format/structure with just a parent-view, child-view and DataProvider(Supports pagination, sorting, filtering and all other operations supported by DataProvider). \n\nThough this extension is mainly intended for RESTful APIs built in Yii 2, it can be used anywhere in the application as explained below.\n\nInstallation\n------------\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n```\nphp composer.phar require codespede/yii2-template-renderer \"*\"\n```\n\nor add\n\n```json\n\"codespede/yii2-template-renderer\": \"*\"\n```\n\nto the `require` section of your composer.json.\n\nUse Cases\n---------\n- Suppose you want to deliver the data in CSV format like below:\n```\ntitle,image,content\nABC,abc.jpg,Content of ABC\nMNO,mno.jpg,Content of MNO\nXYZ,xyz.jpg,Content of XYZ\n```\n - Suppose you have to render the API response in a specific format like below:\n```\n-begin-\n--title=ABC\n--image=abc.jpg\n--content=Content of ABC\n---\n--title=MNO\n--image=mno.jpg\n--content=Content of MNO\n---\n--title=XYZ\n--image=xyz.jpg\n--content=Content of XYZ\n-end-\n```\n - Or in any situation where the you have to deliver custom formatted data through the API.\n\nHow to use\n----------\n\nOne can use this by simply returning the TemplateRenderer object in any action as shown in the below code:\n\n```\npublic function actionRender(){\n    $dataProvider = new ActiveDataProvider(['query' =\u003e Model::find()-\u003ewhere($condition)])\n    return new \\cs\\templaterenderer\\TemplateRenderer([\n        'dataProvider' =\u003e $dataProvider,\n        'parentView' =\u003e '/path/to/parent-view', //path to the parent or wrapper view file\n        'itemView' =\u003e '/path/to/item-view', //path to the item view file\n    ]);\n}\n\n```\n\nIn the `$parentView` file, a placeholder `{{items}}` in the code will be replaced automatically with the collectively rendered result of `$itemView` for the models in the current page.\nFor example, if the content has to be rendered as shown in the second use case above, the `$parentView` file should be like:\n\n```\n-begin-\n{{items}}\n-end-\n```\nand the `$itemView` should be like:\n\n```\n--title=\u003c?=$model-\u003etitle?\u003e\n--image=\u003c?=$model-\u003eimage?\u003e\n--content=\u003c?=$model-\u003econtent?\u003e\n```\n\nAdvantages\n---------\n- The data can be paginated, sorted and filtered just as how it can be done with a GridView or ListView. You can pass the pagination, sort and filter parameters in the URL and the content rendered will be according to the provided parameters.\n- Easy to navigate through paginated content by utilizing Pagination Headers in the response.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodespede%2Fyii2-template-renderer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodespede%2Fyii2-template-renderer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodespede%2Fyii2-template-renderer/lists"}