1
votes

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

2
Well it sounds like you're missing a 'views' directory. Have you created the directory? Is that the correct filepath, should it be /app/views instead?duncan
Yes I have created directory /app/views.mardon
You mean use $app->view->setTemplatesDirectory("/app/views") this product the same errormardon

2 Answers

2
votes

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');
0
votes

My stupid mistake

i must use

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

and I have

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