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 trialKyle Barney
9,081 PointsPHP Code Showing Up As An HTML Comment Rather Than Being Executed
I'm working with the Twig templating language in Workspaces. Ever since I started using Twig the server has stopped executing the other PHP code included in my document. Instead it shows up as an HTML comment (viewable in the dev tools). Other than that, the Slim routing and Twig templating features appear to be working fine. I tried remaking the files to no avail. Any ideas on why this is happening and how to fix it?
1 Answer
Kevin Korte
28,149 PointsI had a suspicion that you can't use regular php in a twig template, because it's getting parsed by twig now, not php. My guess is when twig encounters php or unknown parts, it must put them in html comments so it doesn't error out the page or view.
A quick search confirmed I think I'm right, see if this helps you: http://twig.sensiolabs.org/doc/advanced.html
Kyle Barney
9,081 PointsKyle Barney
9,081 PointsGood call - that did the trick. Looks like once you start using Twig you have to use their way of expressing things rather than the standard PHP way - no mixing. So:
{{ text }}
rather than
<?php echo "text" ?>)
Kevin Korte
28,149 PointsKevin Korte
28,149 PointsYou got it! Their docs have a examples for a few different things you might want to do. Happy coding!