We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

PHP in templates- yay or nay?

How Do I?

From EE Slack's avatar
From EE Slack
185 posts
one year ago
From EE Slack's avatar From EE Slack

It’s not recommended to set templates to allow PHP, right? IF I wanted to set a header using that route…

       
From EE Slack's avatar
From EE Slack
185 posts
one year ago
From EE Slack's avatar From EE Slack

While it is possible to use php in templates (if the allow_php config override is used), it’s not recommended. Performance, accessibility for less technical users, and security are all in play. Plus it’s usually just as easy to spin up an add-on.

? 1
       
mithra62's avatar
mithra62
63 posts
one year ago
mithra62's avatar mithra62

Piling on to add agreement. Allowing PHP in templates opens up a huge entry point for malicious players and makes debugging said PHP a nightmare. Avoid at all costs. As the above said, “spin up an add-on” instead. Always.

       
Hop Studios's avatar
Hop Studios
481 posts
one year ago
Hop Studios's avatar Hop Studios

While the issues raised above are all accurate – security, debug-ability, performance (sometimes) – I would argue there’s a middle ground here:

  • For people using EE for the first time, there’s often a temptation to use PHP in the template because that’s familiar ground, when often there’s an EE-tag-native way, or a great possibly free add-on, that would make the PHP unnecessary. It’s worth the time to investigate that path.

  • For advanced users, PHP in the template is really not that much faster than creating your own add-on and then it’s future-proof, re-useable, safer, etc. etc. Writing huge tools across templates is much harder than creating a packaged add-on.

But there are definitely those times when doing one particular something in a particular template with some custom PHP is absolutely the most efficient and effective way to solve a problem in the moment. So It’s not that PHP-in-template is always a bad idea. It’s just that usually there are better ways to get the outcome you want.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.