{"id":13704077,"url":"https://github.com/rcrowe/TwigBridge","last_synced_at":"2025-05-05T09:32:56.604Z","repository":{"id":5626149,"uuid":"6834113","full_name":"rcrowe/TwigBridge","owner":"rcrowe","description":"Give the power of Twig to Laravel","archived":false,"fork":false,"pushed_at":"2024-04-24T09:04:15.000Z","size":634,"stargazers_count":891,"open_issues_count":102,"forks_count":165,"subscribers_count":47,"default_branch":"master","last_synced_at":"2024-05-22T03:03:19.141Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rcrowe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-11-23T22:56:25.000Z","updated_at":"2024-06-18T10:44:39.454Z","dependencies_parsed_at":"2024-04-24T09:49:08.919Z","dependency_job_id":"9ad9de71-4ee6-4af4-9d10-115adb06a666","html_url":"https://github.com/rcrowe/TwigBridge","commit_stats":{"total_commits":578,"total_committers":68,"mean_commits":8.5,"dds":"0.39792387543252594","last_synced_commit":"639345cb32156ff69845ed471bbf0778c52a28b2"},"previous_names":[],"tags_count":78,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcrowe%2FTwigBridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcrowe%2FTwigBridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcrowe%2FTwigBridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcrowe%2FTwigBridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rcrowe","download_url":"https://codeload.github.com/rcrowe/TwigBridge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224439698,"owners_count":17311506,"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-02T21:01:03.875Z","updated_at":"2024-11-13T11:30:44.600Z","avatar_url":"https://github.com/rcrowe.png","language":"PHP","funding_links":[],"categories":["目录","模板引擎( Templating )"],"sub_categories":["模板 Templating"],"readme":"Allows you to use [Twig](http://twig.sensiolabs.org/) seamlessly in [Laravel](http://laravel.com/).\n\n[![Latest Stable Version](https://poser.pugx.org/rcrowe/twigbridge/v/stable.png)](https://packagist.org/packages/rcrowe/twigbridge)\n[![Total Downloads](https://poser.pugx.org/rcrowe/twigbridge/downloads.png)](https://packagist.org/packages/rcrowe/twigbridge)\n[![test](https://github.com/rcrowe/TwigBridge/actions/workflows/ci.yml/badge.svg)](https://github.com/rcrowe/TwigBridge/actions/workflows/ci.yml)\n[![License](https://poser.pugx.org/rcrowe/twigbridge/license.png)](https://packagist.org/packages/rcrowe/twigbridge)\n\n# Requirements\n\nTwigBridge \u003e= 0.13 supports Twig 3. If you need Twig 1/2 support, use the 0.12 versions.\n\n# Installation\n\nRequire this package with Composer\n\n```bash\ncomposer require rcrowe/twigbridge\n```\n\n# Quick Start\n\nLaravel automatically registers the Service Provider. Use Artisan to publish the twig config file:\n\n```php\nphp artisan vendor:publish --provider=\"TwigBridge\\ServiceProvider\"\n```\n\nAt this point you can now begin using twig like you would any other view\n\n```php\n//app/Http/routes.php\n//twig template resources/views/hello.twig\nRoute::get('/', function () {\n    return View::make('hello');\n});\n```\n\nYou can create the twig files in resources/views with the .twig file extension.\n```bash\nresources/views/hello.twig\n```\n\n# Configuration\n\nOnce Composer has installed or updated your packages you need to register TwigBridge with Laravel itself. Open up config/app.php and find the providers key towards the bottom and add:\n\n```php\n'TwigBridge\\ServiceProvider',\n```\n\nYou can add the TwigBridge Facade, to have easier access to the TwigBridge (or Twig\\Environment).\n\n```php\n'Twig' =\u003e 'TwigBridge\\Facade\\Twig',\n```\n\n```php\nTwig::addExtension('TwigBridge\\Extension\\Loader\\Functions');\nTwig::render('mytemplate', $data);\n```\n\nTwigBridge's configuration file can be extended in your ConfigServiceProvider, under the `twigbridge` key. You can find the default configuration file at `vendor/rcrowe/twigbridge/config`.  \n\nYou _should_ use Artisan to copy the default configuration file from the `/vendor` directory to `/config/twigbridge.php` with the following command:\n\n```bash\nphp artisan vendor:publish --provider=\"TwigBridge\\ServiceProvider\"\n```\n\nIf you make changes to the `/config/twigbridge.php` file you will most likely have to run the `twig:clean` Artisan command for the changes to take effect.\n\n# Installation on Lumen\n\nFor Lumen, you need to load the same Service Provider, but you have to disable the `Auth`, `Translator` and `Url` extensions in your local configuration.\nCopy the `config/twigbridge.php` file to your local `config` folder and register the configuration + Service Provider in `bootstrap/app.php`:\n\n```php\n$app-\u003econfigure('twigbridge');\n$app-\u003eregister('TwigBridge\\ServiceProvider');\n```\n\n# Usage\n\nYou call the Twig template like you would any other view:\n\n```php\n// Without the file extension\nView::make('i_am_twig', [...])\n```\n\nTwigBridge also supports views in other packages:\n\n```php\nView::make('pagination::simple')\n```\n\nThe above rules continue when extending another Twig template:\n\n```html\n{% extends \"parent\" %}\n{% extends \"pagination::parent\" %}\n```\n\nYou can call functions with parameters:\n\n```html\n{{ link_to_route('tasks.edit', 'Edit', task.id, {'class': 'btn btn-primary'}) }}\n```\n\nAnd output variables, escaped by default. Use the `raw` filter to skip escaping.\n\n```html\n{{ some_var }}\n{{ html_var | raw }}\n{{ long_var | str_limit(50) }}\n```\n\n# Extensions\n\nSometimes you want to extend / add new functions for use in Twig templates. Add to the `enabled` array in config/twigbridge.php a list of extensions for Twig to load.\n\n```php\n'enabled' =\u003e array(\n    'TwigBridge\\Extensions\\Example'\n)\n```\n\nTwigBridge supports both a string or a closure as a callback, so for example you might implement the [Assetic](https://github.com/kriswallsmith/assetic) Twig extension as follows:\n\n```php\n'enabled' =\u003e [\n    function($app) {\n        $factory = new Assetic\\Factory\\AssetFactory($app['path'].'/../some/path/');\n        $factory-\u003esetDebug(false);\n        // etc.....\n        return new Assetic\\Extension\\Twig\\AsseticExtension($factory);\n    }\n]\n```\n\nTwigBridge comes with the following extensions enabled by default:\n\n- [Twig\\Extension\\DebugExtension](http://twig.sensiolabs.org/doc/extensions/debug.html)\n- TwigBridge\\Extension\\Laravel\\Auth\n- TwigBridge\\Extension\\Laravel\\Config\n- TwigBridge\\Extension\\Laravel\\Dump\n- TwigBridge\\Extension\\Laravel\\Form\n- TwigBridge\\Extension\\Laravel\\Gate\n- TwigBridge\\Extension\\Laravel\\Html\n- TwigBridge\\Extension\\Laravel\\Input\n- TwigBridge\\Extension\\Laravel\\Session\n- TwigBridge\\Extension\\Laravel\\String\n- TwigBridge\\Extension\\Laravel\\Translator\n- TwigBridge\\Extension\\Laravel\\Url\n- TwigBridge\\Extension\\Loader\\Facades\n- TwigBridge\\Extension\\Loader\\Filters\n- TwigBridge\\Extension\\Loader\\Functions\n\nTo enable '0.5.x' style Facades, enable the Legacy Facades extension:\n- TwigBridge\\Extension\\Laravel\\Legacy\\Facades\n\n\n## FilterLoader and FunctionLoader\n\nThese loader extensions exposes Laravel helpers as both Twig functions and filters.\n\nCheck out the config/twigbridge.php file to see a list of defined function / filters. You can also add your own.\n\n## FacadeLoader\n\nThe FacadeLoader extension allows you to call any facade you have configured in config/twigbridge.php. This gives your Twig templates integration with any Laravel class as well as any other classes you alias.\n\nTo use the Laravel integration (or indeed any aliased class and method), just add your facades to the config and call them like `URL.to(link)` (instead of `URL::to($link)`)\n\n## Functions/Filters/Variables\n\nThe following helpers/filters are added by the default Extensions. They are based on the helpers and/or facades, so should be self explaining.\n\nFunctions:\n * asset, action, url, route, secure_url, secure_asset\n * auth_check, auth_guest, auth_user\n * can\n * config_get, config_has\n * dump\n * form_* (All the Form::* methods, snake_cased)\n * html_* (All the Html::* methods, snake_cased)\n * input_get, input_old, input_has\n * link_to, link_to_asset, link_to_route, link_to_action\n * session_has, session_get, csrf_token, csrf_field, method_field\n * str_* (All the Str::* methods, snake_cased)\n * trans, trans_choice\n * url_* (All the URL::* methods, snake_cased)\n\nFilters:\n * camel_case, snake_case, studly_case\n * str_* (All the Str::* methods, snake_cased)\n * trans, trans_choice\n\nGlobal variables:\n * app: the Illuminate\\Foundation\\Application object\n * errors: The $errors MessageBag from the Validator (always available)\n\n# Artisan Commands\n\nTwigBridge offers a command for CLI Interaction.\n\nEmpty the Twig cache:\n```\n$ php artisan twig:clean\n```\n\nLint all Twig templates:\n```\n$ php artisan twig:lint\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frcrowe%2FTwigBridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frcrowe%2FTwigBridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frcrowe%2FTwigBridge/lists"}