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 Views & Twig Inside of Slim

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

Do I need to understand what's going on here?

Don't worry... this time my website works on localhost. I've followed along with Hampton, looking at the code on the Twig website. But I've just gone through the video a second time and I can't make head or tail of what is happening and what the code snippets mean.

$app = new \Slim\Slim(array(
 'view' => new \Slim\Views\Twig()  //use slim views Twig. define as argument when instantiated as an object
));  //new slim object instance

$view = $app->view();
$view->parserOptions = array(  //set parser options for twig class. 
    'debug' => true
);

//declare and use a twig parser extension
$view->parserExtensions = array(
    new \Slim\Views\TwigExtension(),  //set equal to a twig extension.
);

These comments in my code are as I understand it from the course. If I put this bit there that works as an argument for the function or this thing is a parser extension. But I don't really "get it".

Is that okay so long as I know where to find the information? I've followed the course okay up to now but I'm struggling with these concepts. :)

1 Answer

Kevin Korte
Kevin Korte
28,148 Points

I would say you don't have to worry so much about how it is working, but way more importantly where and why. It's kinda the benefit of using frameworks. It abstracts away much of the grunt and heavy lifting, and packages into a neat little interaction.

So to clarify, I'd slow down enough and read the documentation to learn why you need to set parser options, and where you would find the information to do so.

Of course the more you know, the better, and a lot can be learned by looking at the source code. Hope that helps.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

Thanks Kevin.

Yea I've read the documentation back and it reads like a technical manual so it gives the code but expects you to know something about it. But sometimes I just sit there and things, "yea but what does it mean?" The bit with the helper functions for parseExtensions for example. Great! I know they're there to help but I'm not getting my ahead around why.

And I confess. I wrote my post last night without having actually tested the website on local host. It didn't work.

I don't know why this is... the error messages meant nothing to me, despite looking in on the files mentioned on the errors.

But it doesn't matter now. It looks like I fixed it by getting back into composer and going through the process of reinstalling Twig and Slim. It's a slow process but it's a learning experience isn't it? :-)