# Slim Application Error - View cannot render

**URL:** https://discourse.slimframework.com/t/slim-application-error-view-cannot-render/2114
**Category:** Questions
**Created:** [December 28, 2017, 11:25am UTC](https://discourse.slimframework.com/t/slim-application-error-view-cannot-render/2114 "2017-12-28T11:25:16Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![xpico](https://avatars.discourse-cdn.com/v4/letter/x/9fc348/32.png) [@xpico](https://discourse.slimframework.com/u/xpico)
#### Post date: [December 28, 2017, 11:25am UTC](https://discourse.slimframework.com/t/slim-application-error-view-cannot-render/2114/1 "2017-12-28T11:25:16Z")

</div>

Hi,

I’m new with Slim and I’m trying to do the first aplication tutorial but i have an error.

They say me: View cannot render `tickets.phtml` because the template does not exist

In index.php i put this to set template directory:

`$container['view'] = new \Slim\Views\PhpRenderer("../templates/");`

And this is my folder structure:

```
/project
    /src
        /public
           index.php
       /templates
           tickets.phtml

```

What I’m doing wrong?

Thanks,

---

<div class="post-metadata">

### Author: ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)
#### Post date: [December 28, 2017, 12:01pm UTC](https://discourse.slimframework.com/t/slim-application-error-view-cannot-render/2114/2 "2017-12-28T12:01:42Z")

</div>

Try single quotes around the directory?

```php
$container['view'] = new \Slim\Views\PhpRenderer('../templates/');

```

Otherwise, what I see there looks good.

---

<div class="post-metadata">

### Author: ![xpico](https://avatars.discourse-cdn.com/v4/letter/x/9fc348/32.png) [@xpico](https://discourse.slimframework.com/u/xpico)
#### Post date: [December 28, 2017, 12:26pm UTC](https://discourse.slimframework.com/t/slim-application-error-view-cannot-render/2114/3 "2017-12-28T12:26:41Z")

</div>

I try with single quotes and nothing, continue with same error.

I’m stay debugging and I see in /vendor/slim/php-view/src/PhpRenderer.php in line 153 this:

```
if (!is_file($this->templatePath . $template)) {
        throw new \RuntimeException("View cannot render `$template` because the template does not exist");
}

```

The problem is that $this-\>templatePath . $template is this ‘’…/templates/ticketadd.phtml" and the is\_file function return false, so !false its true and throw that exception.

What do you thing was the problem?

---

<div class="post-metadata">

### Author: ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)
#### Post date: [December 28, 2017, 1:04pm UTC](https://discourse.slimframework.com/t/slim-application-error-view-cannot-render/2114/4 "2017-12-28T13:04:33Z")

</div>

Is the logger successfully logging to `/logs/app.log`?

---

<div class="post-metadata">

### Author: ![xpico](https://avatars.discourse-cdn.com/v4/letter/x/9fc348/32.png) [@xpico](https://discourse.slimframework.com/u/xpico)
#### Post date: [December 28, 2017, 1:25pm UTC](https://discourse.slimframework.com/t/slim-application-error-view-cannot-render/2114/5 "2017-12-28T13:25:45Z")

</div>

Yes, the logger is logging successfully.

This is my logger:

```
$container['logger'] = function($c) {
    $logger = new \Monolog\Logger('Slim_logger');
    $file_handler = new \Monolog\Handler\StreamHandler("../logs/app.log");
    $logger->pushHandler($file_handler);
    return $logger;
};

```

And here is the folder:

```
/project
   /logs
       app.log
   /src
       /public
          index.php
      /templates
          tickets.phtml
```

---

<div class="post-metadata">

### Author: ![xpico](https://avatars.discourse-cdn.com/v4/letter/x/9fc348/32.png) [@xpico](https://discourse.slimframework.com/u/xpico)
#### Post date: [December 28, 2017, 1:32pm UTC](https://discourse.slimframework.com/t/slim-application-error-view-cannot-render/2114/6 "2017-12-28T13:32:26Z")

</div>

in order if I use $container[‘renderer’] instead of $container[‘view’] like this works well:

```
use Slim\Views\PhpRenderer;
$container['renderer'] = new PhpRenderer("./templates");
$app->get('/tickets', function (Request $request, Response $response) {
    $mapper = new TicketMapper($this->db);
    $tickets = $mapper->getTickets();
    $response = $this->renderer->render($response, "tickets.phtml", ["tickets" => $tickets]);
    return $response;
}
```

---

<div class="post-metadata">

### Author: ![llvdl](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/llvdl/32/78_2.png) [@llvdl](https://discourse.slimframework.com/u/llvdl)
#### Post date: [December 31, 2017, 12:20am UTC](https://discourse.slimframework.com/t/slim-application-error-view-cannot-render/2114/7 "2017-12-31T00:20:24Z")

</div>

> [@xpico](#):
>
> $container[‘view’] = new \Slim\Views\PhpRenderer(“../templates/”);

> [@xpico](#):
>
> $container[‘renderer’] = new PhpRenderer(“./templates”);

I think it is because you used `"./templates"` instead of `../templates/`. It seems `./templates` is correct, which is strange because `index.php` is in `/public` 😕

You can use [` __DIR__ `](http://php.net/manual/en/language.constants.predefined.php) for a path relative to the directory of the current file, so you point to a directory regardless of the current directory of the main PHP script. If you use

```php
$container['view'] = new \Slim\Views\PhpRenderer( __DIR__. '/../templates/');

```

in `project/public/index.php`, then it should correctly point to the `/project/templates/` directory.
