Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h1>PHP is a template language.</h1> <p>In my experience so far with various template systems, the conclusion was pretty simple: <em>use none</em>.</p> <p>Instead, write PHP as it should be written! Never do anything inside a .html besides <code>echo</code> and <code>for</code>/<code>foreach</code>. If you write the code based on a design pattern like MVC this becomes even more obvious: just <code>echo</code> and <code>foreach</code> inside and explain the frontends they should never mess with the code inside <code>&lt;?php</code> and <code>?&gt;</code>.</p> <p>It worked for me ever since. It usually was harder for me to explain them Smarty than to explain to never mess with php.</p> <p>Template systems also add weight to your server (sometimes is just a bit, sometimes you may feel it). It may seem over-optimization at first, but I prefer to keep it as simple as it can be.</p> <p><strong>Note:</strong></p> <p>Smarty, for example, is <strong>HARDER</strong> to spot in a .html file because the only Smarty syntax highlighter I know is a NetBeans plugin and it's pretty beta. PHP, on the other hand, has it syntax highlighted in any decent editor. Also easier for the frontends to spot and not mess with.</p> <h1>Wrap up</h1> <h2>Cons (for using template system)</h2> <ul> <li>Increases server load (lighter or heavier, doesn't matter - you can see it)</li> <li>Induces bad practice (logic wrapped inside template language syntax)</li> <li>No syntax highlighting for template languages' syntax - harder to spot (for coder and frontend)</li> <li>Time spent learning it and teaching it to the frontends</li> <li>Harder to explain to the frontend team (I've taught basic PHP to frontends several times - while many more were already able to write their own 'beginner-level' PHP; I have <strong>never</strong> taught a frontend Smarty so they can do something other than <code>{$var}</code> )</li> <li>Makes you avoid the <em>REAL problem</em>: <strong>logic and presentation separation</strong>!</li> <li>Adds extra weight to your project</li> </ul> <h2>Pros (for using template system)</h2> <ul> <li>Extreme boredom (probably the only valid argument)</li> </ul> <h2>Template system replacement</h2> <ul> <li>Logic and presentation separation (I'd suggest <strong>MVC</strong> for this task and for the pros it provides for other fields of development: easier maintenance, abstract database and so on)</li> <li>Force yourself to write in the view only <code>echo</code> and iteration for echoing: <code>foreach</code> and <code>for</code> should accomplish 99% of the iteration needs; you can also use <code>while</code> and <code>do while</code></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload