Can we use PHP in our templates instead of Twig? Is it possible to use strait PHP in our templates along side of Twig and or instead of Twig?

If so how does one go about it?
No this is not possible.

If you really need PHP, you can write a plugin with one of the following:


a Template Variable class, which can be accessed from your templates via craft.myPluginHandle
a Twig extension, which can add its own global filters, functions, or tags, etc.
a controller, which can execute PHP before calling $this-&gt;renderTemplate(...)
a template hook, which allows PHP code to access and modify the current template variable context, wherever the {% hook %} tag is placed.


Why Twig anyway?

The question to use php in templates comes up every once in a while, but there are good reasons for not using it.

For example if Craft changes its code you don't have to worry about your templates. The upcoming update of the Yii framework would force you to rewrite all your templates if they were written in php.

There is also a great article from Fabien Potencier on this topic -- tl;dr php is too verbose for templating.