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 Contact Form & Sending Email Named Routes

Tim Beachum
Tim Beachum
3,095 Points

Slim Error When I run index.php

Here is the error that I am getting:

Slim Application Error The application could not run because of the following error:

Details

Type: Twig_Error_Syntax Message: The function "baseUrl" does not exist in "main.twig" at line 30 File: /home/treehouse/workspace/vendor/twig/twig/lib/Twig/ExpressionParser.php Line: 578 Trace

0 /home/treehouse/workspace/vendor/twig/twig/lib/Twig/ExpressionParser.php(351): Twig_ExpressionParser->getFunctionNodeClass('baseUrl', 30)

1 /home/treehouse/workspace/vendor/twig/twig/lib/Twig/ExpressionParser.php(144): Twig_ExpressionParser->getFunctionNode('baseUrl', 30)

2 /home/treehouse/workspace/vendor/twig/twig/lib/Twig/ExpressionParser.php(84): Twig_ExpressionParser->parsePrimaryExpression()

3 /home/treehouse/workspace/vendor/twig/twig/lib/Twig/ExpressionParser.php(41): Twig_ExpressionParser->getPrimary()

4 /home/treehouse/workspace/vendor/twig/twig/lib/Twig/Parser.php(141): Twig_ExpressionParser->parseExpression()

5 /home/treehouse/workspace/vendor/twig/twig/lib/Twig/Parser.php(95): Twig_Parser->subparse(NULL, false)

6 /home/treehouse/workspace/vendor/twig/twig/lib/Twig/Environment.php(606): Twig_Parser->parse(Object(Twig_TokenStream))

7 /home/treehouse/workspace/vendor/twig/twig/lib/Twig/Environment.php(658): Twig_Environment->parse(Object(Twig_TokenStream))

8 /home/treehouse/workspace/vendor/twig/twig/lib/Twig/Environment.php(396): Twig_Environment->compileSource('...', 'main.twig')

9 /home/treehouse/workspace/vendor/twig/twig/lib/Twig/Template.php(286): Twig_Environment->loadTemplate('main.twig', NULL)

10 /home/treehouse/workspace/vendor/twig/twig/lib/Twig/Environment.php(403) : eval()'d code(11): Twig_Template->loadTemplate('main.twig', 'about.twig', 1)

11 /home/treehouse/workspace/vendor/twig/twig/lib/Twig/Environment.php(411): TwigTemplate_87fa17a43c525a6dd65897900b8b7049d4e2de5230937e2da534aa1c8c9cd199->construct(Object(Twig_Environment))

12 /home/treehouse/workspace/vendor/slim/views/Twig.php(87): Twig_Environment->loadTemplate('about.twig')

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

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

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

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

17 [internal function]: {closure}()

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

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

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

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

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

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

24 /home/treehouse/workspace/index.php(28): Slim\Slim->run()

25 {main}

Dale Severude
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Dale Severude
Full Stack JavaScript Techdegree Graduate 71,349 Points

Hey Tim, Did you ever get this resolved?

Check the href lines of code in main.twig carefully for any typos:

      <a href="{{ baseUrl() }}" class="selected">About</a>
      <a href="{{ siteUrl('/contact') }}">Contact</a>

Also make sure this line of code is available in in your index.php, as this allows you to reference the 4 routing helpers.

$view->parserExtensions = array(
    new \Slim\Views\TwigExtension(),
);