Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
Twig – the Most Popular Stand-Alone PHP Template Engine
Aug 09, 2017 @ 14:17:09

On the SitePoint PHP blog they've posted a tutorial highlighting one of the most widely used templating tools in the PHP ecosystem (that's not locked into a framework) - Twig. In this new tutorial author Claudio Ribeiro introduces you to the tool and what it has to offer you and your application.

Twig is a template engine for PHP. But isn’t PHP itself a template engine? Yes and no!

Even though PHP started as a template engine, it didn’t evolve like one [...]. PHP is a verbose language, and that verbosity is amplified when trying to output HTML content.

Modern template systems will take away some of that verbosity and still add a fair share of functionality on top. Things like security and debug features are mainstays in modern template engines.

Today, we’re focusing on Twig.

He starts off by helping you get the tool installed via Composer and shows it in use to display the values in a hard-coded PHP array. The template (index.html) outputs the result as HTML and shows the use of normal variable output, control structures and filters on the data during output. He then moves on to other topics like working with layouts, caching output, looping, conditionals and filters. The final note is about debugging, mentioning the "dump" function to directly output a value for examination regardless of type.

tagged: twig tutorial introduction template engine

Link: https://www.sitepoint.com/twig-popular-stand-alone-php-template-engine/


Trending Topics: