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

Talha Khalid
Talha Khalid
10,262 Points

Hello All. I am getting the "The function "baseUrl" does not exist in "main.twig" at line 29" message.

Hello All, I am getting a "The function "baseUrl" does not exist in "main.twig" at line 29". parserExtension has been enabled. Any ideas on what is wrong? The code below is where I am getting the message

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

We need either the code pasted here or a snapshot by using the camera icon on the upper right of Workspaces.

4 Answers

Talha Khalid
Talha Khalid
10,262 Points

Hey Ted Sumner. I figured out what the issue was. Had to change out a few things in my index.php file. Thanks

Edited to answer and marked as best to indicate issue resolved.

Talha Khalid
Talha Khalid
10,262 Points

Take a look at the code:

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

should be spelled as parserExtenstions not parerExtensions

Patrick Koch
Patrick Koch
40,498 Points

Hi Talha Khalid,

I have the same error how do you fixed it? I think, its cause I working on my local server, but dont know how to fix it.

greetings Patrick

Talha Khalid
Talha Khalid
10,262 Points

Hey Patrick, could you post the code that you are running from the index.php file? My issue was that I had my commands out of order and thats why it couldn't recognize the baseUrl (or any of the other) functions. Try comparing it to the index.php file in the course notes and see if you can find the difference there.

Patrick Koch
Patrick Koch
40,498 Points

so my index.php file:

<?php
require 'vendor/autoload.php'; 
date_default_timezone_set("Europe/London");

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

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

$view = $app->view();
$view->parserOptions = array(
    'debug' => true
);

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

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

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


$app->run();

?>

Thanks for checking it

greetings Patrick

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

As Talha told, its "parser" not parer. That was the issue.