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 trialNada Mabrouk
3,609 PointsWhy we use twig instead of creating a PHP file and then start including it in every page?
It's about Building a website using slim framework along with Twig as a templating language. the teacher used Twig in order not to repeat the code (DRY concept), but why don't we do the same thing by creating a php file and then start including it instead of changing all the file to twig files !
1 Answer
Jarosław Jarząbek
10,970 PointsReasons for this are listed on twig homepage: http://twig.sensiolabs.org/
When it comes to template engines in PHP, many people will tell you that PHP itself is a template engine. But even if PHP started its life as a template language, it did not evolve like one in the recent years. As a matter of fact, it doesn't support many features modern template engines should have nowadays.
The twig syntax is easy to learn and has been optimized to allow web designers to get their job done fast without getting in their way.
Jason Wist
2,483 PointsJason Wist
2,483 PointsWhat do you mean by creating a PHP file and including it?