{"id":19039625,"url":"https://github.com/windwalker-io/windwalker-view","last_synced_at":"2026-04-09T14:48:20.702Z","repository":{"id":21005521,"uuid":"24296131","full_name":"windwalker-io/windwalker-view","owner":"windwalker-io","description":"[READ ONLY] Subtree split of Windwalker Framework","archived":false,"fork":false,"pushed_at":"2016-04-02T05:37:50.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-02T06:44:55.270Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/ventoviro/windwalker","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/windwalker-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2014-09-21T16:21:51.000Z","updated_at":"2024-12-16T13:49:40.000Z","dependencies_parsed_at":"2022-07-31T05:48:01.929Z","dependency_job_id":null,"html_url":"https://github.com/windwalker-io/windwalker-view","commit_stats":null,"previous_names":["ventoviro/windwalker-view"],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fwindwalker-view","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fwindwalker-view/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fwindwalker-view/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fwindwalker-view/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/windwalker-io","download_url":"https://codeload.github.com/windwalker-io/windwalker-view/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240100160,"owners_count":19747639,"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-08T22:17:56.475Z","updated_at":"2025-12-18T09:05:48.681Z","avatar_url":"https://github.com/windwalker-io.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Windwalker View\n\n## Installation via Composer\n\nAdd this to the require block in your `composer.json`.\n\n``` json\n{\n    \"require\": {\n        \"windwalker/view\": \"~2.0\"\n    }\n}\n```\n\n## Create A Simple View\n\n### AbstractView\n\n`AbstractView` is very simple, it only need a render method to render what you want.\n\n``` php\nuse Windwalker\\View\\AbstractView;\n\nclass MyView extends AbstractView\n{\n    public function render()\n    {\n        $tmpl = \u003c\u003c\u003cTMPL\n# The is a Markdown Article\n\nHello %s~~~!\nTMPL;\n\n        return MyMarkdown::render(sprintf($tmpl, $this-\u003edata['foo']));\n    }\n}\n\n// Create view and set data\n$view = new MyView;\n\n$view-\u003eset('foo', 'World');\n\n$view-\u003erender();\n```\n\nThe Result will be:\n\n``` html\n\u003ch1\u003eThe is a Markdown Article\u003c/h1\u003e\n\nHello World~~~!\n```\n\n### SimpleHtmlView\n\n`SimpleHtmlView` can set a php file to render:\n\n``` php\nuse Windwalker\\View\\SimpleHtmlView;\n\nclass MyHtmlView extends SimpleHtmlView\n{\n    public function prepare($data)\n    {\n        // Format dome data\n        $data['time'] = $data['time']-\u003eformat('Y-m-d H:i:s');\n\n        $data['link'] = '/flower/' . OutputFilter::stringUrlSafe($data['name']) . '.html';\n    }\n}\n\n$view = new MyHtmlView;\n\n$view-\u003eset('time', new DateTime);\n$view-\u003eset('name', $name);\n\n$view-\u003esetLayout('/path/to/template.php')-\u003erender();\n```\n\nThe template file:\n\n``` php\n\u003c?php\n\n$time = $data['time'];\n?\u003e\n\u003cp\u003e\n    Now is: \u003c?php echo $this-\u003eescape($time); ?\u003e\n\n    I'm:\n    \u003ca href=\"\u003c?php echo $data['link'] ?\u003e\"\u003e\n        \u003c?php echo $this-\u003eescape($data['name']); ?\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n```\n\n## HtmlView\n\n`HtmlView` is more powerful than `SimpleHtmlView`, we can set [Renderer](https://github.com/ventoviro/windwalker-renderer)\n as a render engine into it, and find template in several paths.\n\n``` php\nuse Windwalker\\View\\HtmlView;\n\n$paths = new SplPriorityQueue;\n$paths-\u003einsert('path/of/system', 300);\n$paths-\u003einsert('path/of/theme', 500);\n\n$data = array(\n    'time' =\u003e new DateTime\n);\n\n$view = new HtmlView($data, new PhpRenderer($paths));\n\n$view-\u003esetLayout('foo')-\u003erender(); // Will find foo.php in every paths.\n```\n\nSee also: [Windwalker Renderer](https://github.com/ventoviro/windwalker-renderer)\n\n### Extends It\n\n``` php\nuse Windwalker\\View\\HtmlView;\nuse Windwalker\\Renderer\\BladeRenderer;\n\n// A Blade View\nclass BladeHtmlView extends HtmlView\n{\n    public function __construct($data = array(), BladeRenderer $renderer = null)\n    {\n        $renderer = $renderer ? : new BladeRenderer('default/path', array('cache_path' =\u003e 'cache/path'))\n\n        parent::__construct($data, $renderer);\n    }\n}\n\n// View for different MVC structures\nclass ArticleHtmlView extends BladeHtmlView\n{\n    public function prepare($data)\n    {\n        $data['time'] = $data['time']-\u003eformat('Y-m-d H:i:s');\n    }\n}\n\n$view = new MyHtmlView;\n\n$view-\u003e['time'] = new DateTime; // Use array access\n\n$view-\u003esetLayout('template')-\u003erender(); // Will find template.blade.php\n```\n\n### The Data object\n\nHtmlView use `Windwalker\\Data\\Data` as data store, we don't need to worry about data exists or not.\n\n``` php\n\u003c?php\n\n$time = $data['time']; // Exists\n$name = $data['name']; // Not exists, just return null.\n$title = $data-\u003etitle; // Also support object access.\n```\n\nSee [Windwalker Data](https://github.com/ventoviro/windwalker-data)\n\n## JsonView\n\nJsonView use Registry as data store, we can separate different level by dot(.).\n\n``` php\n$view = new JsonView;\n\n$view['foo.bar'] = 'baz';\n\n$view-\u003erender();\n```\n\nThe result will be:\n\n``` json\n{\n    \"foo\": {\n        \"bar\": \"baz\"\n    }\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindwalker-io%2Fwindwalker-view","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwindwalker-io%2Fwindwalker-view","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindwalker-io%2Fwindwalker-view/lists"}