Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Twital is a "plugin" for Twig that adds some sugar syntax, which makes its templates similar to PHPTal or VueJS.

License

NotificationsYou must be signed in to change notification settings

goetas/twital

Repository files navigation

Build StatusScrutinizer Quality ScoreCode CoverageGitHub licensePackagist

What is Twital?

Twital is a template engine built on top ofTwig(a template engine for PHP and default template engine on Symfony)that adds some shortcuts and makes Twig's syntax more suitable for HTML based (XML, HTML5, XHTML, SGML) templates.Twital takes inspiration fromPHPTal,TALandAngularJS orVue.js (just for some aspects),mixing their language syntaxes with the powerful Twig templating engine system.

Twital is fully compatible with Twig, all Twig templates can be rendered using Twital.

To better understand the Twital's benefits, consider the followingTwital template, whichsimply shows a list of users from an array:

<ult:if="users">    <lit:for="user in users">        {{ user.name }}    </li></ul>

To do the same thing using Twig, you need:

{%ifusers%}    <ul>{%foruserinusers%}            <li>                {{ user.name }}            </li>{%endfor%}    </ul>{%endif%}

As you can see, the Twital template ismore readable,less verbose andandyou don't have to worry about opening and closing block instructions(they are inherited from the HTML structure).

One of the main advantages of Twital is theimplicit presence of control statements, which makestemplates more readable and less verbose. Furthermore, it has all Twig functionalities,such as template inheritance, translations, looping, filtering, escaping, etc.

If some Twig functionality is not directly available for Twital,you canfreely mix Twig and Twital syntaxes.

In the example below, we have mixed Twital and Twig syntaxes to use Twig custom tags:

<h1t:if="users">    {% custom_tag %}        {{ someUnsafeVariable }}    {% endcustom_tag %}</h1>

When needed, you can extend from a Twig template:

<t:extendsfrom="layout.twig">        <t:blockname="content">        Hello {{name}}!    </t:block>    </t:extends>

You can also extend from Twig a Twital template:

{%extends"layout.twital"%}{%blockcontent%}    Hello {{name}}!{%endblock%}

A presentation of Twital features and advantages is available onthis presentation.

Installation

The recommended ways install Twital is viaComposer.

composer require goetas/twital

Documentation

Go herehttp://twital.readthedocs.org/ to read a more detailed documentation about Twital.

Getting started

First, you have to create a file that contains your template(named for exampledemo.twital.html):

<divt:if="name">    Hello {{ name }}</div>

Afterwards, you have to create a PHP script that instantiate the required objects:

require_once'/path/to/composer/vendor/autoload.php';useGoetas\Twital\TwitalLoader;$fileLoader =newTwig_Loader_Filesystem('/path/to/templates');$twitalLoader =newTwitalLoader($fileLoader);$twig =newTwig_Environment($twitalLoader);echo$twig->render('demo.twital.html',array('name' =>'John'));

That's it!

Symfony Users

If you are aSymfony user, you can add Twital to your project using theTwitalBundle.

The bundle integrates all most common functionalities as Assetic, Forms, Translations, Routing, etc.

Twig Users

Starting from version Twital 1.0.0, both twig 1.x and 2.x versions are supported.

Note

The code in this project is provided under theMIT license.For professional supportcontactgoetas@gmail.comor visithttps://www.goetas.com


[8]ページ先頭

©2009-2025 Movatter.jp