mardon
mardon

Reputation: 1125

twig error when using in slim

Hi I need interate twig to Slim application, I install twig with composer and im my script I have

<?php

use Slim\Slim;
use Slim\Views\Twig;

use Noodlehaus\Config;

use Codecourse\User\User;

session_cache_limiter(false);
session_start();

ini_set('display_errors','On');

define('INC_ROOT', dirname(__DIR__));

require INC_ROOT.'/vendor/autoload.php';

$app = new Slim([
    'mode' => file_get_contents(INC_ROOT.'/mode.php'),
    'view' => new Twig(),
    'template.path' => INC_ROOT . '/app/views'
]);
$app->view->setTemplatesDirectory("/views");

$app->configureMode($app->config('mode'), function() use ($app) {
    $app->config = Config::load(INC_ROOT . "/app/config/{$app->mode}.php");
});



echo $app->config->get('db.driver');

require 'database.php';

$app->container->set('user', function() {
    return new User;
});

$app->get('/', function() use ($app) {
    $app->render('home.php');
});

when I run script I obtain this error:

Type: Twig_Error_Loader

Message: The "/views" directory does not exist.

File: C:\xampp\htdocs\authentication\vendor\twig\twig\lib\Twig\Loader\Filesystem.php

Upvotes: 1

Views: 654

Answers (2)

mardon
mardon

Reputation: 1125

My stupid mistake

i must use

'templates.path' => INC_ROOT . '/app/views'

and I have

'template.path' => INC_ROOT . '/app/views'

Upvotes: 0

Adam Elsodaney
Adam Elsodaney

Reputation: 7818

The Slim documentation for configuring the template path might be a little misleading; you only need to set template.path or call View::setTemplatesDirectory but not both.

If you wanted to use the latter, then it would simply be :

$app->view->setTemplatesDirectory(INC_ROOT . '/app/views');

Upvotes: 2

Related Questions