{"id":13828395,"url":"https://github.com/goetas/twital","last_synced_at":"2025-04-06T21:16:21.977Z","repository":{"id":13709541,"uuid":"16403499","full_name":"goetas/twital","owner":"goetas","description":"Twital is a \"plugin\" for Twig that adds some sugar syntax, which makes its templates similar to PHPTal or VueJS.","archived":false,"fork":false,"pushed_at":"2021-12-21T09:35:48.000Z","size":1216,"stargazers_count":128,"open_issues_count":6,"forks_count":13,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-05-05T14:02:56.805Z","etag":null,"topics":["angularjs","html5","php","phptal","template-engine","twig","twig-syntax","twig-templates","xml"],"latest_commit_sha":null,"homepage":"http://twital.readthedocs.org","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"ShimmerResearch/shimmer3","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goetas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-31T08:50:49.000Z","updated_at":"2024-03-12T16:29:22.000Z","dependencies_parsed_at":"2022-07-30T16:08:45.735Z","dependency_job_id":null,"html_url":"https://github.com/goetas/twital","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goetas%2Ftwital","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goetas%2Ftwital/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goetas%2Ftwital/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goetas%2Ftwital/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goetas","download_url":"https://codeload.github.com/goetas/twital/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247550690,"owners_count":20956987,"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":["angularjs","html5","php","phptal","template-engine","twig","twig-syntax","twig-templates","xml"],"created_at":"2024-08-04T09:02:44.532Z","updated_at":"2025-04-06T21:16:21.957Z","avatar_url":"https://github.com/goetas.png","language":"PHP","funding_links":[],"categories":["PHP","Twig"],"sub_categories":["Extensions"],"readme":"[![Build Status](https://travis-ci.org/goetas/twital.png?branch=dev)](https://travis-ci.org/goetas/twital)\n[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/goetas/twital/badges/quality-score.png?s=617ac058fc3c486427752fd3fb1f3931bca971ed)](https://scrutinizer-ci.com/g/goetas/twital/)\n[![Code Coverage](https://scrutinizer-ci.com/g/goetas/twital/badges/coverage.png?s=de8d714be4a97b4b11bb44a2ff6601dbda86696c)](https://scrutinizer-ci.com/g/goetas/twital/)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/goetas/twital/master/LICENSE)\n[![Packagist](https://img.shields.io/packagist/v/goetas/twital.svg)](https://packagist.org/packages/goetas/twital)\n\nWhat is Twital?\n==============\n\nTwital is a template engine built on top of [Twig](http://twig.sensiolabs.org/) \n(a template engine for PHP and default template engine on Symfony) \nthat adds some shortcuts and makes Twig's syntax more suitable for HTML based (XML, HTML5, XHTML, SGML) templates.\nTwital takes inspiration from [PHPTal](http://phptal.org/), [TAL](http://en.wikipedia.org/wiki/Template_Attribute_Language) \nand [AngularJS](http://angularjs.org/) or [Vue.js](https://vuejs.org/) (just for some aspects), \nmixing their language syntaxes with the powerful Twig templating engine system.\n\nTwital is fully compatible with Twig, all Twig templates can be rendered using Twital.\n\nTo better understand the Twital's benefits, consider the following **Twital** template, which\nsimply shows a list of users from an array:\n\n```xml\n\u003cul t:if=\"users\"\u003e\n    \u003cli t:for=\"user in users\"\u003e\n        {{ user.name }}\n    \u003c/li\u003e\n\u003c/ul\u003e\n```\n\nTo do the same thing using Twig, you need:\n\n```jinja\n{% if users %}\n    \u003cul\u003e\n        {% for user in users %}\n            \u003cli\u003e\n                {{ user.name }}\n            \u003c/li\u003e\n        {% endfor %}\n    \u003c/ul\u003e\n{% endif %}\n```\n\nAs you can see, the Twital template is **more readable**, **less verbose** and\nand **you don't have to worry about opening and closing block instructions** \n(they are inherited from the HTML structure).\n\n\nOne of the main advantages of Twital is the *implicit* presence of control statements, which makes\ntemplates more readable and less verbose. Furthermore, it has all Twig functionalities,\nsuch as template inheritance, translations, looping, filtering, escaping, etc.\n\nIf some Twig functionality is not directly available for Twital, \nyou can **freely mix Twig and Twital** syntaxes. \n\nIn the example below, we have mixed Twital and Twig syntaxes to use Twig custom tags:\n\n```xml\n\u003ch1 t:if=\"users\"\u003e\n    {% custom_tag %}\n        {{ someUnsafeVariable }}\n    {% endcustom_tag %}\n\u003c/h1\u003e\n```\n\nWhen needed, you can extend from a Twig template:\n\n```xml\n\u003ct:extends from=\"layout.twig\"\u003e\n    \n    \u003ct:block name=\"content\"\u003e\n        Hello {{name}}!\n    \u003c/t:block\u003e\n    \n\u003c/t:extends\u003e\n```\n\nYou can also extend from Twig a Twital template:\n```jinja\n{% extends \"layout.twital\" %}\n    \n{% block content %}\n    Hello {{name}}!\n{% endblock %}\n    \n\n```\n\nA presentation of Twital features and advantages is available on [this presentation](https://goetas.bitbucket.io/twital-02-08-2016-berlin-ug/#/).\n\n\nInstallation\n------------\n\nThe recommended ways install Twital is via [Composer](https://getcomposer.org/).\n\n\n```bash\ncomposer require goetas/twital\n```\n\nDocumentation\n-------------\n\nGo here http://twital.readthedocs.org/ to read a more detailed documentation about Twital.\n\n\nGetting started\n---------------\n\nFirst, you have to create a file that contains your template\n(named for example `demo.twital.html`):\n\n```xml\n\u003cdiv t:if=\"name\"\u003e\n    Hello {{ name }}\n\u003c/div\u003e\n```\n\nAfterwards, you have to create a PHP script that instantiate the required objects:\n\n```php\nrequire_once '/path/to/composer/vendor/autoload.php';\nuse Goetas\\Twital\\TwitalLoader;\n\n$fileLoader = new Twig_Loader_Filesystem('/path/to/templates');\n$twitalLoader = new TwitalLoader($fileLoader);\n\n$twig = new Twig_Environment($twitalLoader);\necho $twig-\u003erender('demo.twital.html', array('name' =\u003e 'John'));\n```\n\nThat's it!\n\n\nSymfony Users\n--------------\n\nIf you are a [Symfony](http://symfony.com/) user, you can add Twital to your project using the \n[TwitalBundle](https://github.com/goetas/twital-bundle).\n\nThe bundle integrates all most common functionalities as Assetic, Forms, Translations, Routing, etc.\n\nTwig Users\n----------\n\nStarting from version Twital 1.0.0,  both twig 1.x and 2.x versions are supported. \n\n\n## Note \n\nThe code in this project is provided under the \n[MIT](https://opensource.org/licenses/MIT) license. \nFor professional support \ncontact [goetas@gmail.com](mailto:goetas@gmail.com) \nor visit [https://www.goetas.com](https://www.goetas.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoetas%2Ftwital","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoetas%2Ftwital","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoetas%2Ftwital/lists"}