{"id":13622320,"url":"https://github.com/slimphp/Slim-Views","last_synced_at":"2025-04-15T05:34:37.607Z","repository":{"id":8828000,"uuid":"10528851","full_name":"slimphp/Slim-Views","owner":"slimphp","description":"Slim Framework 2 custom views","archived":true,"fork":false,"pushed_at":"2022-02-10T05:03:21.000Z","size":419,"stargazers_count":307,"open_issues_count":16,"forks_count":54,"subscribers_count":27,"default_branch":"master","last_synced_at":"2024-04-14T17:01:59.547Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/slimphp.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":"2013-06-06T14:52:02.000Z","updated_at":"2024-02-14T06:56:59.000Z","dependencies_parsed_at":"2022-08-08T19:00:03.994Z","dependency_job_id":null,"html_url":"https://github.com/slimphp/Slim-Views","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/slimphp%2FSlim-Views","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slimphp%2FSlim-Views/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slimphp%2FSlim-Views/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slimphp%2FSlim-Views/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slimphp","download_url":"https://codeload.github.com/slimphp/Slim-Views/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223661530,"owners_count":17181687,"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-08-01T21:01:17.610Z","updated_at":"2024-11-08T09:31:28.016Z","avatar_url":"https://github.com/slimphp.png","language":"PHP","readme":"# Slim Views\r\n\r\nThis repository contains custom View classes for the template frameworks listed below. \r\nYou can use any of these custom View classes by either requiring the appropriate class in your \r\nSlim Framework bootstrap file and initialize your Slim application using an instance of \r\nthe selected View class or using Composer (the recommended way).\r\n\r\nSlim Views only officially support the following views listed below.\r\n\r\n- Smarty\r\n- Twig\r\n\r\n## How to Install\r\n\r\n#### using [Composer](http://getcomposer.org/)\r\n\r\nInstall in your project by running the following composer command:\r\n\r\n```bash\r\n$ php composer require slim/views\r\n```\r\n\r\n## Smarty\r\n\r\n### How to use\r\n    \r\n```php\r\n\u003c?php\r\nrequire 'vendor/autoload.php';\r\n\r\n$app = new \\Slim\\Slim(array(\r\n    'view' =\u003e new \\Slim\\Views\\Smarty()\r\n));\r\n```\r\n\r\nTo use Smarty options do the following:\r\n    \r\n```php\r\n$view = $app-\u003eview();\r\n$view-\u003eparserDirectory = dirname(__FILE__) . 'smarty';\r\n$view-\u003eparserCompileDirectory = dirname(__FILE__) . '/compiled';\r\n$view-\u003eparserCacheDirectory = dirname(__FILE__) . '/cache';\r\n```\r\n\r\n## Twig\r\n\r\n### How to use\r\n    \r\n```php\r\n\u003c?php\r\nrequire 'vendor/autoload.php';\r\n\r\n$app = new \\Slim\\Slim(array(\r\n    'view' =\u003e new \\Slim\\Views\\Twig()\r\n));\r\n```\r\n\r\nTo use Twig options do the following:\r\n    \r\n```php\r\n$view = $app-\u003eview();\r\n$view-\u003eparserOptions = array(\r\n    'debug' =\u003e true,\r\n    'cache' =\u003e dirname(__FILE__) . '/cache'\r\n);\r\n```\r\n\r\nIn addition to all of this we also have a few helper functions which are included for both view parsers.\r\nIn order to start using these you can add them to their respective view parser as stated below:\r\n\r\n#### Twig\r\n\r\n```php\r\n$view-\u003eparserExtensions = array(\r\n    new \\Slim\\Views\\TwigExtension(),\r\n);\r\n```\r\n\r\n#### Smarty\r\n\r\n```php\r\n$view-\u003eparserExtensions = array(\r\n    dirname(__FILE__) . '/vendor/slim/views/Slim/Views/SmartyPlugins',\r\n);\r\n```\r\n\r\nThese helpers are listed below.\r\n\r\n- urlFor\r\n- siteUrl\r\n- baseUrl\r\n- currentUrl\r\n\r\n#### urlFor\r\n\r\n__Twig__\r\n\r\nInside your Twig template you would write:\r\n\r\n    {{ urlFor('hello', {\"name\": \"Josh\", \"age\": \"19\"}) }}\r\n\r\nYou can easily pass variables that are objects or arrays by doing:\r\n\r\n    \u003ca href=\"{{ urlFor('hello', {\"name\": person.name, \"age\": person.age}) }}\"\u003eHello {{ name }}\u003c/a\u003e\r\n\r\nIf you need to specify the appname for the getInstance method in the urlFor functions, set it as the third parameter of the function\r\nin your template:\r\n\r\n    \u003ca href=\"{{ urlFor('hello', {\"name\": person.name, \"age\": person.age}, 'admin') }}\"\u003eHello {{ name }}\u003c/a\u003e\r\n\r\n__Smarty__\r\n\r\nInside your Smarty template you would write:\r\n\r\n    {urlFor name=\"hello\" options=\"name.Josh|age.26\"}\r\n\r\nor with the new array syntax:\r\n\r\n    {urlFor name=\"hello\" options=[\"name\" =\u003e \"Josh\", \"age\" =\u003e \"26\"]}\r\n\r\nYou can easily pass variables that are arrays as normal or using the (.):\r\n\r\n    \u003ca href=\"{urlFor name=\"hello\" options=\"name.{$person.name}|age.{$person.age}\"}\"\u003eHello {$name}\u003c/a\u003e\r\n\r\nIf you need to specify the appname for the getInstance method in the urlFor functions, set the appname parameter in your function:\r\n\r\n    \u003ca href=\"{urlFor name=\"hello\" appname=\"admin\" options=\"name.{$person.name}|age.{$person.age}\"}\"\u003eHello {$name}\u003c/a\u003e\r\n\r\n#### siteUrl\r\n\r\n__Twig__\r\n\r\nInside your Twig template you would write:\r\n\r\n    {{ siteUrl('/about/me') }}\r\n\r\n__Smarty__\r\n\r\nInside your Smarty template you would write:\r\n\r\n    {siteUrl url='/about/me'}\r\n\r\n\r\n#### baseUrl\r\n\r\n__Twig__\r\n\r\nInside your Twig template you would write:\r\n\r\n    {{ baseUrl() }}\r\n\r\n__Smarty__\r\n\r\nInside your Smarty template you would write:\r\n\r\n    {baseUrl}\r\n\r\n\r\n#### currentUrl\r\n\r\n__Twig__\r\n\r\nInside your Twig template you would write:\r\n\r\n    {{ currentUrl() }}\r\n\r\n__Smarty__\r\n\r\nInside your Smarty template you would write:\r\n\r\n    {currentUrl}\r\n\r\n## Authors\r\n\r\n[Josh Lockhart](https://github.com/codeguy)\r\n\r\n[Andrew Smith](https://github.com/silentworks)\r\n\r\n## License\r\n\r\nMIT Public License","funding_links":[],"categories":["其他微型框架 Micro Framework Extras","Table of Contents","PHP","目录","Packages and Middleware"],"sub_categories":["Micro Framework Extras","微观框架-扩展 micro-framework-extras","Videos"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslimphp%2FSlim-Views","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslimphp%2FSlim-Views","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslimphp%2FSlim-Views/lists"}