lundi 13 février 2017

How to use the PHP template engine in Twig instead of the Twig syntax within Silex 2

Vote count: 0

In Silex2 I am able to use Twig templates but I want to use the PHP engine of Twig, instead of the Twig syntax. For example this guide describes how to do it for Symfony but not Silex 2.

My Silex index.php looks like:

$app->register(new Silex\Provider\TwigServiceProvider(), array(
    'twig.path' => __DIR__.'/views',
));

$app->get('/', function() use ($app) {
    return $app['twig']->render('index.html.php', array(
        'name' => 'Bob',
    ));
});

My index.html.php looks like:


Welcome to the index name; ?>

When I run the app in the browser and view the source, I see the literal string name; ?> which hasn't been executed.

I suspect there may be a Twig config setting to tell it I want to use the PHP style templates. To clarify, if I use the Twig syntax instead, e.g.:


Welcome to the index

Then it works and I see the name Bob, therefore I know this is not a web server or PHP config problem.

asked 2 mins ago

Let's block ads! (Why?)



How to use the PHP template engine in Twig instead of the Twig syntax within Silex 2

Aucun commentaire:

Enregistrer un commentaire