{"id":20206999,"url":"https://github.com/koolreport/twig","last_synced_at":"2025-03-03T09:44:49.049Z","repository":{"id":57008491,"uuid":"188527738","full_name":"koolreport/twig","owner":"koolreport","description":"Use Twig template engine in KoolReport","archived":false,"fork":false,"pushed_at":"2020-11-10T16:00:20.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-14T02:56:40.709Z","etag":null,"topics":["mysql-reporting-tools","php-reporting-tools","reporting-tools","template-engine","twig","twig-engine","twig-templates"],"latest_commit_sha":null,"homepage":"https://www.koolreport.com/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koolreport.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2019-05-25T06:09:11.000Z","updated_at":"2020-11-10T16:00:22.000Z","dependencies_parsed_at":"2022-08-21T14:31:26.359Z","dependency_job_id":null,"html_url":"https://github.com/koolreport/twig","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koolreport%2Ftwig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koolreport%2Ftwig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koolreport%2Ftwig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koolreport%2Ftwig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koolreport","download_url":"https://codeload.github.com/koolreport/twig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241644543,"owners_count":19996177,"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":["mysql-reporting-tools","php-reporting-tools","reporting-tools","template-engine","twig","twig-engine","twig-templates"],"created_at":"2024-11-14T05:27:05.029Z","updated_at":"2025-03-03T09:44:49.027Z","avatar_url":"https://github.com/koolreport.png","language":"PHP","readme":"# Twig\n\n## Overview\n\nStarting from version 4.0.0, KoolReport supports other template engines rather than just its own template view file. `Twig` is one of the popular template engines that KoolReport supports.\n\n## Installation\n\n#### By downloading .zip file\n\n1. [Download](https://www.koolreport.com/packages/twig)\n2. Unzip the zip file\n3. Copy the folder `twig` into `koolreport` folder so that look like below\n\n```bash\nkoolreport\n├── core\n├── twig\n```\n\n#### By composer\n\n```\ncomposer require koolreport/twig\n```\n\n## Get started\n\n__Step 1:__ Add the twig service to your report\n\n```\nclass Report extends \\koolreport\\KoolReport\n{\n    use \\koolreport\\clients\\Bootstrap;\n\n    use \\koolreport\\twig\\Engine;\n    protected function twigInit()\n    {\n        $loader = new \\Twig\\Loader\\FilesystemLoader(dirname(__FILE__).'/views');\n        $twig = new \\Twig\\Environment($loader);\n        return $twig;\n    }\n    ...\n}\n```\n\n__Step 2:__ Create the view `report.html` inside `views` folder like below:\n\n```\n\u003chtml\u003e\n\u003chead\u003e\n    \u003ctitle\u003eWelcome to Twig\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003ch1\u003eWelcome to Twig\u003c/h1\u003e\n    {{ \n        widget('koolreport.widgets.koolphp.Table',{\n            dataSource:report.dataStore(\"data\"),\n        }) \n    }}\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n__Step 3:__ You can run your report with following line of code\n\n```\n$report = new Report;\n$report-\u003erun()-\u003erender(\"report.html\");\n```\n\n__Congrat__, Now you can use Twig to design your report.\n\n\n## Some notes:\n\n1. In your template, you refer to report object with parameter `report`\n2. When use function `widget()` to generate koolreport's widget, you should change the backslash `\\` in the class name to dot `\".\"`, for example, you change: `\\koolreport\\widgets\\koolphp\\Table` to `koolreport.widgets.koolphp.Table`\n3. You can reference to any datastore with `report.dataStore(\"name_of_datastore\")`\n\n## Limitation\n\nThere are some limitation due to the fact that `Twig` does not allow PHP to run within. This limits some of capability of KoolReport's widget such as defining anonymous function. For example, there is no way to define custom function to format value in Table widget like this.\n\n```\nTable::create(array(\n    ...\n    \"columns\"=\u003earray(\n        \"id\"=\u003earray(\n            \"formatValue\"=\u003efunction($value)\n            {\n                return \"\u003ca href='$value'\u003eView\u003c/a\u003e\";\n            }\n        )\n    )\n))\n```\n\nSimply it is not able to transform above php code to json definition in twig.\n\n# Resources\n\n1. [Full documentation](https://www.koolreport.com/docs/twig/overview/)\n2. [Examples \u0026 Demonstration](https://www.koolreport.com/examples)\n\n\n# Support\n\nPlease use [our forum](https://www.koolreport.com/forum/topics) if you need support, by this way other people can benefit as well. If the support request need privacy, you may send email to us at [support@koolreport.com](mailto:support@koolreport.com).","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoolreport%2Ftwig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoolreport%2Ftwig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoolreport%2Ftwig/lists"}