What is TwitalBundle?

TwitalBundle is a Symfony bundle that integrates the Twital template engine into Synfony2. This enables you to use all Twig/Symfony functionalities with the Twital template engine language syntax.

To learn more about Twital, you can read the dedicated documentation.

Install

The recommended way to install TwitalBundle is via Composer:

composer require 'goetas/twital-bundle'

If you are using SymfonyFlex, the bundle will be automatically enabled and configured, otherwise follow the next steps.

Enable the bundle

To enable the bundle in the kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Goetas\TwitalBundle\GoetasTwitalBundle(),
        //..
    );
}

Configure

If you are using SymfonyFlex, the bundle is auto-configured and you can skip this step.

If you are using the symfony templating component (available in Symfony 2.x and 3.x), you have to enable the twital template engine inside your config.yml.

framework:
    templating:
        engines: ['twig', 'twital']

Optional Configurations

Here are some optional configurations for the bundle.

Source Adapters

By default Twital parses *.html.twital, *.xml.twital and *.xhtml.twital files. If you want you can customize the file types automatically parsed by Twital.

goetas_twital:
    # extra file extension matching
    source_adapter:
        - { service: twital.source_adapter.xml, pattern: ['/\.xml\.twital$/', '/\.atom\.twital$/'] }
        - { service: twital.source_adapter.html5, pattern: ['/\.html\.twital$/', '/\.htm\.twital$/'] }
        - { service: twital.source_adapter.xhtml, pattern: ['/\.xhtml\.twital$/'] }

Twital comes with the following source adapters that you can use to parse your template files:

  • twital.source_adapter.html5: used for most of the HTML-style templates
  • twital.source_adapter.xml: used for strictly XML-compliant templates
  • twital.source_adapter.xhtml: used for strictly XHTML-compliant templates (similar to XML but with some XHTML customizations)

Full Twig Compatibility

The following template is a valid Twig template, but is not a valid HTML5 document (the div tag can contain only attributes). Because of it, the Twital source adapters will not be able to parse the template.

<div {% if foo %} class="row" {% endif %}>
    Hello World
</div>

You can also enable a full Twig compatibility mode to allow this kind of templates.

goetas_twital:
    full_twig_compatibility: true

Integration

TwitalBundle comes with all features that are already supported by TwigBundle (forms, translations, assetic, routing, etc).

Contributing

This is an open source project - contributions are welcome. If your are interested, you can contribute to documentation, source code, test suite or anything else!

To start contributing right now, go to https://github.com/goetas/twital-bundle and fork it!

You can read some tips to improve your contributing experience looking into https://github.com/goetas/twital-bundle/blob/master/CONTRIBUTING.md present inside the root directory of Twital GIT repository.

Contents

Note

I’m sorry for the terrible english fluency used inside the documentation, I’m trying to improve it. Pull Requests are welcome.