Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Building Websites with PHP Slim Basics & Twig Templates Layouts with Twig

Mihai Tabla
Mihai Tabla
6,493 Points

Slim Application Error

I get the error when I view the file:

Slim Application Error

The application could not run because of the following error: Details Type: RuntimeException Message: Cannot set the Smarty lib directory : . Directory does not exist. File: /home/treehouse/workspace/vendor/slim/views/Smarty.php Line: 104 Trace

0 /home/treehouse/workspace/vendor/slim/views/Smarty.php(87): Slim\Views\Smarty->getInstance()

1 /home/treehouse/workspace/vendor/slim/slim/Slim/View.php(255): Slim\Views\Smarty->render('about.twig', NULL)

2 /home/treehouse/workspace/vendor/slim/slim/Slim/View.php(243): Slim\View->fetch('about.twig', NULL)

3 /home/treehouse/workspace/vendor/slim/slim/Slim/Slim.php(757): Slim\View->display('about.twig')

4 /home/treehouse/workspace/index.php(22): Slim\Slim->render('about.twig')

5 [internal function]: {closure}()

6 /home/treehouse/workspace/vendor/slim/slim/Slim/Route.php(468): call_user_func_array(Object(Closure), Array)

7 /home/treehouse/workspace/vendor/slim/slim/Slim/Slim.php(1357): Slim\Route->dispatch()

8 /home/treehouse/workspace/vendor/slim/slim/Slim/Middleware/Flash.php(85): Slim\Slim->call()

9 /home/treehouse/workspace/vendor/slim/slim/Slim/Middleware/MethodOverride.php(92): Slim\Middleware\Flash->call()

10 /home/treehouse/workspace/vendor/slim/slim/Slim/Middleware/PrettyExceptions.php(67): Slim\Middleware\MethodOverride->call()

11 /home/treehouse/workspace/vendor/slim/slim/Slim/Slim.php(1302): Slim\Middleware\PrettyExceptions->call()

12 /home/treehouse/workspace/index.php(29): Slim\Slim->run()

13 {main}

Code : main.twig <!doctype html>

<html lang="en"> <head> {% block head %} <meta charset="utf-8"> <title>{% block title %}Ralph Waldo Emerson{% endblock head %}</title> <meta name="description" content="Ralph Waldo Emerson"> <meta name="author" content="Treehouse"> <link href='http://fonts.googleapis.com/css?family=Roboto:400,700' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="css/master.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script src="js/global.js"></script> {% endblock head %} </head>

<body> <!-- <div id="feedback" class="success"> <h3>Success!</h3> <p>You're reading all about Emerson.</p> </div> -->

<header> <h1>Ralph Waldo Emerson</h1> <nav> <a href="index.html" class="selected">About</a> <a href="contact.html">Contact</a> </nav> </header>

<div class="emerson"> {% block hero %}<img src="images/emerson.jpg" alt="Picture of Ralph Waldo Emerson"> {% endblock hero %} </div>

<main> {% block content %} {% endblock content %} </main>

<footer> {% block footer %} <p>A project from <strong><a href="http://teamtreehouse.com">Treehouse</a></strong></p> <nav> <a href="index.html" class="selected">About</a> <a href="contact.html">Contact</a> </nav> {% endblock footer %} </footer>

</body> </html>

about.twig {% extends 'main.twig' %}

{% block content %} <strong>About</strong> <h2>Ralph Waldo Emerson</h2>

<p>Ralph Waldo Emerson <em>(May 25, 1803 – April 27, 1882)</em> was an American essayist, lecturer, and poet, who led the Transcendentalist movement of the mid-19th century. He was seen as a champion of individualism and a prescient critic of the countervailing pressures of society, and he disseminated his thoughts through dozens of published essays and more than 1,500 public lectures across the United States.</p>

<p>Emerson gradually moved away from the religious and social beliefs of his contemporaries, formulating and expressing the philosophy of Transcendentalism in his 1836 essay, Nature. Following this ground-breaking work, he gave a speech entitled "The American Scholar" in 1837, which Oliver Wendell Holmes, Sr. considered to be America's "Intellectual Declaration of Independence".</p>

<p>Emerson wrote most of his important essays as lectures first, then revised them for print. His first two collections of essays – Essays: First Series and Essays: Second Series, published respectively in 1841 and 1844 – represent the core of his thinking, and include such well-known essays as Self-Reliance, The Over-Soul, Circles, The Poet and Experience. Together with Nature, these essays made the decade from the mid-1830s to the mid-1840s Emerson's most fertile period.</p>

<p>Emerson wrote on a number of subjects, never espousing fixed philosophical tenets, but developing certain ideas such as individuality, freedom, the ability for humankind to realize almost anything, and the relationship between the soul and the surrounding world. Emerson's "nature" was more philosophical than naturalistic: "Philosophically considered, the universe is composed of Nature and the Soul." Emerson is one of several figures who "took a more pantheist or pandeist approach by rejecting views of God as separate from the world.""
</p>
<p>He remains among the linchpins of the American romantic movement, and his work has greatly influenced the thinkers, writers and poets that have followed him. When asked to sum up his work, he said his central doctrine was "the infinitude of the private man." Emerson is also well known as a mentor and friend of fellow Transcendentalist Henry David Thoreau.</p>

<p><em>Learn more about Ralph Waldo Emerson from <a href="http://en.wikipedia.org/wiki/Ralph_Waldo_Emerson">Wikipedia</a></em></p>

{% endblock content %}

index.php <?php require 'vendor/autoload.php'; date_default_timezone_set ('Europe/Bucharest');

//$log = new Logger('name'); //$log->pushHandler(new StreamHandler('app.txt', Logger::WARNING)); //$log->addWarning('Foo');

$app = new \Slim\Slim( array( 'view' => new \Slim\Views\Smarty() ));

$view = $app->view(); $view->parserOptions = array( 'debug' => true ); $view->parserExtensions = array( new \Slim\Views\TwigExtension(), );

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

$app->get('/contact', function() use($app){ $app->reder('contact.twig'); });

$app->run();

contact.twig

<!doctype html>

<html lang="en"> <head> <meta charset="utf-8"> <title>Ralph Waldo Emerson</title> <meta name="description" content="Ralph Waldo Emerson"> <meta name="author" content="Treehouse"> <link rel="stylesheet" href="css/master.css"> <link href='http://fonts.googleapis.com/css?family=Roboto:400,700' rel='stylesheet' type='text/css'> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script src="js/global.js"></script> </head>

<body>

<!-- <div id="feedback" class="fail"> <a class="dismiss">Dismiss</a> <h3>Oops!</h3> <p>Looks like you forgot to enter your email address.</p> </div> -->

<header> <h1>Ralph Waldo Emerson</h1> <nav> <a href="index.html">About</a> <a href="contact.html" class="selected">Contact</a> </nav> </header>

<div class="emerson"> <img src="images/emerson.jpg" alt="Picture of Ralph Waldo Emerson"> </div>

<main> <strong>Contact</strong> <h2>Ralph Waldo Emerson</h2>

<p>Unfortately, Ralph Waldo Emerson has been deceased for over 100 years so he's not particularly expediant at replying to email but you can make an attempt below. However, if you require face to gravestone contact you can visit his remains at:</p>
<address>
  <h4>Sleepy Hollow Cemetery</h4>
  <p>34 Bedford Street<br>
  Concord, MA 01742, United States<br>
<a href="https://www.google.com/maps/place/Sleepy+Hollow+Cemetery/@42.464126,-71.343098,15z/data=!4m2!3m1!1s0x0:0x9c41d0f83df689a6?sa=X&ei=ZCgLVZb5Io_hoASc7oHwCQ&ved=0CH0Q_BIwCw">Google Map</a></p>
</address>

<form>
  <fieldset>
    <input type="text" placeholder="Full Name">
    <input type="email" placeholder="Email Address">
    <textarea placeholder="Your message..."></textarea>
  </fieldset>
  <input type="submit" class="button">
</form>

</main>

<footer> <p>A project from <strong><a href="http://teamtreehouse.com">Treehouse</a></strong></p> <nav> <a href="index.html">About</a> <a href="contact.html" class="selected">Contact</a> </nav> </footer> </body> </html>

What seems to be the problem ?

2 Answers

Bryan Manhollan
PLUS
Bryan Manhollan
Courses Plus Student 10,096 Points

Still looking over it all. One thing I do see is you forgot a "n" in render.

$app->get('/contact', function() use($app){ $app->reder('contact.twig'); });

should be :

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

That is toward the bottom of your post. Try fixing that first and see if it helps any.