Eu quero condicionar a saída de HTML para gerar uma página, então qual'é a maneira mais fácil de ecoar trechos multilinha de HTML no PHP 4+? Eu precisaria usar um framework de template como o Smarty?
echo '<html>', "\n"; // I'm sure there's a better way!
echo '<head>', "\n";
echo '</head>', "\n";
echo '<body>', "\n";
echo '</body>', "\n";
echo '</html>', "\n";
Você poderia usar a sintaxe alternativa de sintaxe para estruturas de controle e sair do php:
<?php if ($something): ?>
<some /> <tags /> <etc />
<?=$shortButControversialWayOfPrintingAVariable ?>
<?php /* A comment not visible in the HTML but is a bit of a pain to write */ ?>
<?php else: ?>
<!-- else -->
<?php endif; ?>
Eu sou parcial neste estilo:
<html>
<head>
<% if (X)
{
%> <title>Definitely X</title>
<% }
else
{
%> <title>Totally not X</title>
<% }
%> </head>
</html>
Eu uso etiquetas ao estilo ASP, sim. A mistura de PHP e HTML parece super legível para os meus olhos. O truque está em obter os marcadores <%
e %>
simplesmente certo.