HAML Symfony bundle using the MtHaml PHP HAML parser.
- Acts as a Twig preprocessor: Supports Twig functions, filters, macros, blocks, inheritance, expressions and every Twig features
- Mix Twig and HAML templates: You can include, extend, use and import Twig templates from HAML templates, and vice versa.
- High performance: Templates are compiled to PHP code and cached, no parsing or runtime overhead.
- HAML syntax supported by editors
Ultimately, the MtHaml files should be downloaded to the vendor/MtHaml directory, and the MtHamlBundle files to the vendor/bundles/MtHamlBundle directory.
This can be done in several ways, depending on your preference. The first method is the standard Symfony2 method.
$ composer require mthaml/mthaml-bundle:dev-master
(You can skip Step 2 if you are using this method as Composer will handle autoloading for you.)
Add the following lines in your deps file:
[MtHaml]
git=git://github.com/arnaud-lb/MtHaml.git
target=MtHaml
[MtHamlBundle]
git=git://github.com/arnaud-lb/MtHamlBundle.git
target=bundles/MtHamlBundle
Now, run the vendors script to download the bundle:
$ php bin/vendors install
If you prefer instead to use git submodules, the run the following:
$ git submodule add git://github.com/arnaud-lb/MtHamlBundle.git vendor/bundles/MtHamlBundle
$ git submodule add git://github.com/arnaud-lb/MtHaml.git vendor/MtHaml
$ git submodule update --init
You can skip this step if you used composer to install the bundle.
Add the MtHaml
and MtHamlBundle
namespaces to your autoloader:
<?php
// app/autoload.php
$loader->registerNamespaces(array(
// ...
'MtHaml' => __DIR__ . '/../vendor/MtHaml/lib',
'MtHamlBundle' => __DIR__ . '/../vendor/bundles',
));
Finally, enable the bundle in the kernel:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new MtHamlBundle\MtHamlBundle(),
);
}
# app/config/config.yml
framework:
# ...
templating:
engines: ['haml','twig']
# required, for Symfony to load the bundle configuration
mt_haml:
(This is required, for Symfony to load the bundle configuration.)
/**
* @Template(engine="haml")
*/
public function fooAction() {
The @Haml
annotation is a sub class of @Template
with engine
set to haml
by default.
/**
* @Haml
*/
public function fooAction() {
public function bazAction() {
$this->render('FooBundle:Bar:baz.html.haml');
}
/**
* @View(engine="haml")
*/
public function fooAction() {
See MtHaml docs
The mthaml:debug:dump command compiles a HAML templates into Twig and displays the resulting Twig template.
For debug purposes.
Example:
php ./app/console mthaml:debug:dump AcmeDemoBundle:Demo:index.html.haml