{"id":14966464,"url":"https://github.com/yiisoft/view","last_synced_at":"2025-10-06T21:58:00.130Z","repository":{"id":32836259,"uuid":"143982156","full_name":"yiisoft/view","owner":"yiisoft","description":"Yii view rendering library","archived":false,"fork":false,"pushed_at":"2025-07-20T15:14:12.000Z","size":662,"stargazers_count":56,"open_issues_count":2,"forks_count":48,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-09-17T06:40:59.425Z","etag":null,"topics":["hacktoberfest","mvc","view","widgets","yii3"],"latest_commit_sha":null,"homepage":"https://www.yiiframework.com/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yiisoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"open_collective":"yiisoft","github":["yiisoft"],"polar":"yiisoft"}},"created_at":"2018-08-08T08:12:43.000Z","updated_at":"2025-07-20T15:14:14.000Z","dependencies_parsed_at":"2023-12-25T17:27:08.817Z","dependency_job_id":"a0a853ed-62d1-43c1-b70b-a1929c5a0b0b","html_url":"https://github.com/yiisoft/view","commit_stats":{"total_commits":336,"total_committers":34,"mean_commits":9.882352941176471,"dds":0.6369047619047619,"last_synced_commit":"55ef6628cfb8a3546358e5ec066c23e108a71261"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/yiisoft/view","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yiisoft","download_url":"https://codeload.github.com/yiisoft/view/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fview/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278686629,"owners_count":26028325,"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","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["hacktoberfest","mvc","view","widgets","yii3"],"created_at":"2024-09-24T13:36:25.284Z","updated_at":"2025-10-06T21:58:00.108Z","avatar_url":"https://github.com/yiisoft.png","language":"PHP","funding_links":["https://opencollective.com/yiisoft","https://github.com/sponsors/yiisoft","https://polar.sh/yiisoft"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/yiisoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://yiisoft.github.io/docs/images/yii_logo.svg\" height=\"100px\" alt=\"Yii\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eYii View Rendering Library\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\n[![Latest Stable Version](https://poser.pugx.org/yiisoft/view/v)](https://packagist.org/packages/yiisoft/view)\n[![Total Downloads](https://poser.pugx.org/yiisoft/view/downloads)](https://packagist.org/packages/yiisoft/view)\n[![Build status](https://github.com/yiisoft/view/actions/workflows/build.yml/badge.svg)](https://github.com/yiisoft/view/actions/workflows/build.yml)\n[![Code Coverage](https://codecov.io/gh/yiisoft/view/graph/badge.svg?token=V9PmRxWk9L)](https://codecov.io/gh/yiisoft/view)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fview%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/view/master)\n[![Static analysis](https://github.com/yiisoft/view/actions/workflows/static.yml/badge.svg?branch=master)](https://github.com/yiisoft/view/actions/workflows/static.yml?query=branch%3Amaster)\n[![type-coverage](https://shepherd.dev/github/yiisoft/view/coverage.svg)](https://shepherd.dev/github/yiisoft/view)\n\nThis library provides templates rendering abstraction supporting layout-view-subview hierarchy, custom renderers with\nPHP-based as default, and more. It's used in [Yii Framework](https://www.yiiframework.com/) but is usable separately.\n\n## Requirements\n\n- PHP 8.1 or higher.\n\n## Installation\n\nThe package could be installed with [Composer](https://getcomposer.org):\n\n```shell\ncomposer require yiisoft/view\n```\n\n## General usage\n\nThe package provides two use cases for managing view templates:\n\n- [Basic functionality](docs/guide/en/basic-functionality.md) for use in any environment.\n- Advanced functionality for [use in a web environment](docs/guide/en/use-in-web-environment.md).\n\n### State of `View` and `WebView` services\n\nWhile being immutable and, by itself, stateless, both `View` and `WebView` services have sets of stateful and mutable\ndata.\n\n`View` service:\n- parameters,\n- blocks,\n- theme,\n- locale.\n\n`WebView` service:\n- parameters,\n- blocks,\n- theme,\n- locale,\n- title,\n- meta and link tags,\n- JS/CSS strings,\n- JS/CSS files.\n\nThe state of `View` and `WebView` isn't cloned when the services are cloned. So when\nusing `with*()`, both new and old instances are sharing the same set of stateful mutable data. It allows, for example,\nto get `WebView` via type-hinting in a controller and change context path:\n\n```php\nfinal class BlogController {\n    private WebView $view;\n    public function __construct (WebView $view) {\n        $this-\u003eview = $view-\u003ewithContextPath(__DIR__.'/views');\n    }\n}\n```\n\nand then register CSS in a widget:\n\n```php\nfinal class LastPosts extends Widget \n{    \n    private WebView $view;\n    public function __construct (WebView $view) {\n        $this-\u003eview = $view;\n    }\n    protected function run(): string\n    {\n        ...\n        $this-\u003eview-\u003eregisterCss('.lastPosts { background: #f1f1f1; }');\n        ...\n    }\n}\n```\n\n#### Locale state\n\nYou can change the locale by using `setLocale()`, which will be applied to all other instances that used current state\nincluding existing ones. If you need to change the locale only for a single instance, you can use the immutable\n`withLocale()` method. Locale will be applied to all views rendered within views with `render()` calls.\n\nExample with mutable method:\n\n```php\nfinal class LocaleMiddleware implements MiddlewareInterface\n{    \n    ...\n    private WebView $view;\n    ...\n    public function __construct (\n        ...\n        WebView $view\n        ...\n    ) {\n        $this-\u003eview = $view;\n    }\n    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface\n    {\n        ...\n        $this-\u003eview-\u003esetLocale($locale);\n        ...\n    }\n}\n```\n\nExample with immutable method:\n\n```php\nfinal class BlogController {\n    private WebView $view;\n    public function __construct (WebView $view) {\n        $this-\u003eview = $view;\n    }\n    public function index() {\n        return $this-\u003eview-\u003ewithLocale('es')-\u003erender('index');\n    }\n}\n```\n\n#### Reset state\n\nTo get a deep cloned `View` or `WebView` with a reset state use `withClearedState()`: \n\n```php\n$view = $view-\u003ewithClearedState();\n```\n\n#### Deep clone\n\nTo get a deep cloned `View` or `WebView`, including state cloning, use `deepClone()` method:\n\n```php\n$view = $view-\u003edeepClone();\n```\n\n## Extensions\n  \n- [Yii View Renderer](https://github.com/yiisoft/yii-view-renderer) - a wrapper that's used in\n  [Yii Framework](https://www.yiiframework.com/).\n  Adds extra functionality for a web environment and compatibility \n  with [PSR-7](https://www.php-fig.org/psr/psr-7) interfaces.\n- [yiisoft/view-twig](https://github.com/yiisoft/view-twig) - an extension that provides a view renderer that will\n  allow you to use the [Twig](https://twig.symfony.com) view template engine, instead of the default PHP renderer.\n\n## Documentation\n\n- Guide: [English](docs/guide/en/README.md), [Português - Brasil](docs/guide/pt-BR/README.md)\n- [Internals](docs/internals.md)\n\nIf you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.\nYou may also check out other [Yii Community Resources](https://www.yiiframework.com/community).\n\n## License\n\nThe Yii View Rendering Library is free software. It's released under the terms of the BSD License.\nPlease see [`LICENSE`](./LICENSE.md) for more information.\n\nMaintained by [Yii Software](https://www.yiiframework.com/).\n\n### Support the project\n\n[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective\u0026logoColor=7eadf1\u0026labelColor=555555)](https://opencollective.com/yiisoft)\n\n### Follow updates\n\n[![Official website](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](https://www.yiiframework.com/)\n[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter\u0026logoColor=1DA1F2\u0026labelColor=555555?style=flat)](https://twitter.com/yiiframework)\n[![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat\u0026logo=telegram)](https://t.me/yii3en)\n[![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat\u0026logo=facebook\u0026logoColor=ffffff)](https://www.facebook.com/groups/yiitalk)\n[![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat\u0026logo=slack)](https://yiiframework.com/go/slack)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Fview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyiisoft%2Fview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Fview/lists"}