Search code examples
symfonytwigvolt

Is there a way to use Volt templates in Symfony2?


I'm developing a system where a Phalcon server is responsible for a site frontend while a Symfony2 server is responsible for the content management. The content manager contains an WYSIWYG editor and thus displays the content using the same layout and style as the frontend. I realize Volt and Twig and very similar, but some things like includes and blocks have specific syntax or limitations. We can create our templates/themes in a way that is completely compatible, but that would not be very flexible.

Is there a way to use Volt templates in Symfony2? Or a practical way to convert templates automatically (by hand is not an option here)?


Solution

  • I think in your specific use case the most practical would be to use Twig with Phalcon. In your DI you can load a different engine for that, see the Phalcon Incubator project for the Twig-adapter.

    In short it comes down to using (after adding the Incubator to your project, for instance with Composer):

    $view->registerEngines(
        array(".twig" => 'Phalcon\Mvc\View\Engine\Twig')
    );
    

    instead of

    $view->registerEngines(array(
        ".volt" => 'Phalcon\Mvc\View\Engine\Volt'
    ));
    

    The link describes a more complete step-by-step guide.