{"id":25423377,"url":"https://github.com/jxy918/swoft-smarty","last_synced_at":"2025-09-25T22:49:30.953Z","repository":{"id":57003554,"uuid":"203129872","full_name":"jxy918/swoft-smarty","owner":"jxy918","description":"sowft框架smarty模板组件(Sawft framework smart template component )","archived":false,"fork":false,"pushed_at":"2019-10-24T08:25:18.000Z","size":43,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-01T12:38:57.716Z","etag":null,"topics":["php","smarty","swoft","swoft-ddz","swoft-game","swoft-smarty","swoole"],"latest_commit_sha":null,"homepage":"","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/jxy918.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":"2019-08-19T08:22:32.000Z","updated_at":"2021-12-02T07:32:00.000Z","dependencies_parsed_at":"2022-08-21T12:10:49.126Z","dependency_job_id":null,"html_url":"https://github.com/jxy918/swoft-smarty","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jxy918%2Fswoft-smarty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jxy918%2Fswoft-smarty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jxy918%2Fswoft-smarty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jxy918%2Fswoft-smarty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jxy918","download_url":"https://codeload.github.com/jxy918/swoft-smarty/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239207416,"owners_count":19599963,"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":["php","smarty","swoft","swoft-ddz","swoft-game","swoft-smarty","swoole"],"created_at":"2025-02-16T22:38:31.004Z","updated_at":"2025-09-25T22:49:25.910Z","avatar_url":"https://github.com/jxy918.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swoft-smarty\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/jxy918/swoft-smarty.svg)](https://packagist.org/packages/jxy918/swoft-smarty)\n[![Php Version](https://img.shields.io/badge/php-%3E=7.1-brightgreen.svg?maxAge=2592000)](https://secure.php.net/)\n[![Swoft Doc](https://img.shields.io/badge/docs-passing-green.svg?maxAge=2592000)](https://www.swoft.org/docs)\n[![Swoft License](https://img.shields.io/hexpm/l/plug.svg?maxAge=2592000)](https://github.com/swoft-cloud/swoft/blob/master/LICENSE)\n\nsowft框架smarty模板组件\n\nsmarty template component for swoft.\n\nSwoft-smarty Component\n\n\n## Install, 安装\n\n- composer install command\n\n```\ncomposer require jxy918/swoft-smarty\n\n```\n\n- smarty default config\n- swoft框架里 smarty 的默认配置如下, 默认不需要添加, 如果想要修改, 可以把下面配置放入到bean.php里面, 进行相应的修改即可\n\n```\n'smarty' =\u003e [\n    'debugging'=\u003etrue,\n    'caching'=\u003etrue,\n    'cacheLifetime'=\u003e120,\n    'leftDelimiter' =\u003e '\u003c!--{',\n    'rightDelimiter' =\u003e '}--\u003e',\n    'templateDir' =\u003e '@base/resource/template',\n    'compileDir' =\u003e '@base/runtime/template_c',\n    'cacheDir' =\u003e '@base/runtime/cache'\n]\n```\n\n## Use in Controller, 控制器里使用如下\n\n- app/Http/Controlle/SmartyController.php\n- resource/template/smarty.html\n\napp/Http/Controlle/SmartyController.php\n\n```\n\u003c?php declare(strict_types=1);\n\n\nnamespace App\\Http\\Controller;\n\nuse Swoft;\nuse ReflectionException;\nuse Swoft\\Bean\\Exception\\ContainerException;\nuse Swoft\\Http\\Message\\ContentType;\nuse Swoft\\Http\\Message\\Response;\nuse Swoft\\Http\\Server\\Annotation\\Mapping\\Controller;\nuse Swoft\\Http\\Server\\Annotation\\Mapping\\RequestMapping;\n\n/**\n * Class SmartyController\n *\n * @since 2.0\n *\n * @Controller(prefix=\"smarty\")\n */\nclass SmartyController\n{\n    /**\n     * @RequestMapping(\"index\")\n     * @return Response\n     * @throws ContainerException\n     * @throws ReflectionException\n     * @throws \\Swoft\\Exception\\SwoftException\n     */\n    public function assign(): Response\n    {\n        $tpl = Swoft::getBean('smarty')-\u003einitView();\n        $data = ['nickname'=\u003e'jxy918', 'sex'=\u003e'男', 'msg'=\u003e' hello smarty'];\n        $tpl-\u003eassign('data', $data);\n        $content = $tpl-\u003efetch('smarty.html');\n        return context()-\u003egetResponse()-\u003ewithContentType(ContentType::HTML)-\u003ewithContent($content);\n    }\n}\n\n\n```\n\n模板文件 resource/template/smarty.html\n\n```\n\u003c!doctype html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003cmeta name=\"viewport\"\n          content=\"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0\"\u003e\n    \u003cmeta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\"\u003e\n    \u003ctitle\u003etest smayrt\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003cdiv\u003e\n    \u003cdiv\u003e\n        \u003ch1\u003eHello Smarty\u003c/h1\u003e\n    \u003c/div\u003e\n    \u003cul\u003e\n        \u003c!--{foreach key=k item=v from=$data}--\u003e\n        \u003cli\u003e\u003c!--{$k}--\u003e:\u003c!--{$v}--\u003e\u003c/li\u003e\n        \u003c!--{/foreach}--\u003e\n    \u003c/ul\u003e\n\u003c/div\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjxy918%2Fswoft-smarty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjxy918%2Fswoft-smarty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjxy918%2Fswoft-smarty/lists"}