Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From a maintenance perspective, one should have the HTML / XML as separate from the code as possible IMO, so that minor changes can be made easily even by a non-technical person. </p> <p>The more a homogeneous block the markup is, the cleaner the work.</p> <p>One way to achieve this is to prepare as much as possible in variables, and using the <a href="http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc" rel="noreferrer">heredoc syntax</a>:</p> <pre><code>// Preparation $var1 = get_value("yxyz"); $var2 = get_url ("abc"); $var3 = ($count = 0 ? "Count is zero" : "Count is not zero"); $var4 = htmlentities(get_value("def")); // Output echo &lt;&lt;&lt;EOT &lt;fieldset title="$var4"&gt; &lt;ul class="$var1"&gt; &lt;li&gt; $var2 &lt;/li&gt; &lt;/ul&gt; &lt;/fieldset&gt; EOT; </code></pre> <p>You will want to use more sensible variable names, of course.</p> <p><strong>Edit:</strong> The link pointed out by @stesch in the comments provides some good arguments towards using a <strong>serializer</strong> when producing XML, and by extension, even HTML, instead of printing it out as shown above. I don't think a serializer is necessary in <em>every</em> situation, especially from a maintenance standpoint where templates are <em>so</em> much more easy to edit, but the link is well worth a read. <a href="http://hsivonen.iki.fi/producing-xml/#noescaping" rel="noreferrer"><strong>HOWTO Avoid Being Called a Bozo When Producing XML</strong></a></p> <p>Another big advantage of the separation between logic and content is that if transition to a templating engine, or the introduction of caching becomes necessary one day, it's almost painless to implement because logic and code are already separated.</p>
 

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