Book Image

Symfony2 Essentials

Book Image

Symfony2 Essentials

Overview of this book

Table of Contents (17 chapters)
Symfony2 Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The Twig templating engine


When Symfony1 was created, the framework did not use any of existing template systems but relied on just the PHP as a template language. It had some advantages (that is, templates did not require any processing and were very fast), but wasn't too friendly for frontend developers. Also, PHP is a very verbose language and you need to write a lot of code to do some basic stuff such as checking a variable and determining whether it exists or is empty. Also, escaping variables requires some coding.

In Symfony2, a new templating engine, called Twig, was introduced. Twig was written with a few concepts in mind, such as:

  • Templating system is extensible: Developer may write their own extensions to it very easily.

  • Fast: The written template is compiled and processed, generating an optimized PHP code on the output.

  • More secure: It is much easier to make code secure using Twig with features such as auto-escape or sandboxing.

  • Optimized for frontend development: The Twig syntax...