All Projects → goetas → Twital

goetas / Twital

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

Projects that are alternatives of or similar to Twital

Html5
HTML5学习、总结、实践
Stars: ✭ 493 (+325%)
Mutual labels:  html5, angularjs
Sheetjs
📗 SheetJS Community Edition -- Spreadsheet Data Toolkit
Stars: ✭ 28,479 (+24450.86%)
Mutual labels:  xml, html5
Faqguru
🎒 🚀 🎉 A list of interview questions. This repository is everything you need to prepare for your technical interview.
Stars: ✭ 4,653 (+3911.21%)
Mutual labels:  html5, angularjs
T Shirts
The first OpenSource t-shirts (probably)
Stars: ✭ 300 (+158.62%)
Mutual labels:  html5, angularjs
Onthefly
🔗 Generate TinySVG, HTML and CSS on the fly
Stars: ✭ 37 (-68.1%)
Mutual labels:  xml, angularjs
Mmark
Mmark: a powerful markdown processor in Go geared towards the IETF
Stars: ✭ 313 (+169.83%)
Mutual labels:  xml, html5
J2html
Java to HTML generator. Enjoy typesafe HTML generation.
Stars: ✭ 604 (+420.69%)
Mutual labels:  html5, template-engine
MulleScion
🌱 A modern template engine for Objective C
Stars: ✭ 14 (-87.93%)
Mutual labels:  twig, template-engine
Microzz.github.io
💻https://microzz.com IT技术分享
Stars: ✭ 29 (-75%)
Mutual labels:  html5, angularjs
Treefrog Framework
TreeFrog Framework : High-speed C++ MVC Framework for Web Application
Stars: ✭ 885 (+662.93%)
Mutual labels:  xml, template-engine
Http Rpc
Lightweight REST for Java
Stars: ✭ 298 (+156.9%)
Mutual labels:  xml, template-engine
Emerald
HTML5 templating engine for Nimrod
Stars: ✭ 91 (-21.55%)
Mutual labels:  html5, template-engine
Hstardoc
My blogs write with markdown.
Stars: ✭ 297 (+156.03%)
Mutual labels:  html5, angularjs
Thymeleaf Spring
Thymeleaf integration module for Spring
Stars: ✭ 349 (+200.86%)
Mutual labels:  xml, template-engine
view-twig
Yii View Twig Renderer
Stars: ✭ 24 (-79.31%)
Mutual labels:  twig, template-engine
Learning Resources
"Technology Gold mine" to collect and share materials/resources
Stars: ✭ 573 (+393.97%)
Mutual labels:  html5, angularjs
Magento2-Twig
Twig Template Engine for Magento2
Stars: ✭ 58 (-50%)
Mutual labels:  twig, template-engine
korte
Kotlin cORoutines Template Engine for Multiplatform Kotlin
Stars: ✭ 69 (-40.52%)
Mutual labels:  twig, template-engine
Macsvg
macSVG - An open-source macOS app for designing HTML5 SVG (Scalable Vector Graphics) art and animation with a WebKit web view ➤➤➤
Stars: ✭ 789 (+580.17%)
Mutual labels:  xml, html5
Awesome Twig
A curated list of amazingly awesome Twig extensions, snippets and tutorials
Stars: ✭ 63 (-45.69%)
Mutual labels:  twig, template-engine

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].