• Stars
    star
    127
  • Rank 282,790 (Top 6 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 11 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

Build Status Scrutinizer Quality Score Code Coverage GitHub license Packagist

What is Twital?

Twital is a template engine built on top of Twig (a template engine for PHP and default template engine on Symfomy) that adds some shortcuts and makes Twig's syntax more suitable for HTML based (XML, HTML5, XHTML, SGML) templates. Twital takes inspiration from PHPTal, TAL and AngularJS or Vue.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 following Twital template, which simply shows a list of users from an array:

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

To do the same thing using Twig, you need:

{% if users %}
    <ul>
        {% for user in users %}
            <li>
                {{ user.name }}
            </li>
        {% endfor %}
    </ul>
{% endif %}

As you can see, the Twital template is more readable, less verbose and and you 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 the implicit presence of control statements, which makes templates 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 can freely mix Twig and Twital syntaxes.

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

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

When needed, you can extend from a Twig template:

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

You can also extend from Twig a Twital template:

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

A presentation of Twital features and advantages is available on this presentation.

Installation

The recommended ways install Twital is via Composer.

composer require goetas/twital

Documentation

Go here http://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 example demo.twital.html):

<div t: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';
use Goetas\Twital\TwitalLoader;

$fileLoader = new Twig_Loader_Filesystem('/path/to/templates');
$twitalLoader = new TwitalLoader($fileLoader);

$twig = new Twig_Environment($twitalLoader);
echo $twig->render('demo.twital.html', array('name' => 'John'));

That's it!

Symfony Users

If you are a Symfony user, you can add Twital to your project using the TwitalBundle.

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 the MIT license. For professional support contact [email protected] or visit https://www.goetas.com

More Repositories

1

xsd2php

Convert XSD into PHP classes and serialize into XML (deserialize too)
PHP
149
star
2

webservices

Pure PHP SOAP server and client
PHP
22
star
3

MultipartUploadBundle

Symfony multipart/related/mixed/alternative content type handler (rfc1341).
PHP
22
star
4

twital-bundle

Twital integration for Symfony
PHP
19
star
5

to-swift-mime-parser

Parse a generic mail stream, and convert it to a SwiftMailer Message http://swiftmailer.org/
PHP
12
star
6

messenger-doctrine-outbox

Transactional outbox implementation for Symfony messenger (https://microservices.io/patterns/data/transactional-outbox.html)
PHP
11
star
7

xsd-reader

Read XSD into PHP (see http://goetas.github.io/xsd-reader/)
PHP
9
star
8

apache-fop

Symfony2 Apache FOP Bundle
PHP
7
star
9

xml-xsd-encoder

Convert PHP to XML and viceversa using XML Schema definition as encoding style
PHP
5
star
10

jms-serializer-phpstan-extension

JMS/Serializer extension for PHPStan
PHP
3
star
11

doctrine2xsd

Convert Doctrine2 XML mapping into XSD XML Schema
PHP
2
star
12

TemplatedUriRouter

Symfony RFC-6570 compatible router and URL Generator
PHP
2
star
13

fit-tracker

Demo application with Symfony 2.8, API, AngularJS, REST, PHPUnit
JavaScript
1
star
14

xmldom

PHP DOMDocument improved
PHP
1
star
15

docker-nginx-redirect

Handle HTTP redirects with this simple docker image
Dockerfile
1
star
16

atal

ATal is a templating engine for PHP 5.3+. Atal is inspired to PHPTAL but solves the problem in a more modern way.
PHP
1
star
17

fo-simil-css

Simil CSS for XSL FO
PHP
1
star
18

composer-resolve

1
star
19

xhtml-clsss-to-style

Convert CSS rules into local styles (HTML)
PHP
1
star
20

wsdl-reader

PHP
1
star
21

symfony-mem-leak

https://travis-ci.org/goetas/symfony-mem-leak
PHP
1
star
22

goetas-xsd-reader

PHP
1
star
23

xsd2php-symfony

PHP
1
star
24

TemplatedUriBundle

Symfony Bundle that provides a RFC-6570 compatible router and URL Generator.
PHP
1
star