I really don't see the difference between these. How is the templating any better? I don't just don't understand it or how I could convince someone to use it I work with. I understand "separation" of concerns, but I haven't had huge issues. Isn't the first example generating multiple <li>
tags just like an echo
would? And, I would use php as the "templating language," so I'm not concerned with Smarty or some other system. Thanks.
Why should I use templating system in PHP?
<h1><?=$title?></h1>
<ul>
<?php foreach ($items as $item) {?>
<li><?=$item?></li>
<?php } ?>
</ul>
and (some snippet I found in a forum for an example):
echo "<table>";
for ($i = 0; $i < $largestArray; $i++)
{
echo "<tr>";
if ($i < $array1Size)
{
echo "<td>";
echo $array1[$i];
echo "</td>";
}
else
{
echo "<td>";
echo "null";
echo "</td>";
}
if ($i < $array2Size)
{
echo "<td>";
echo $array2[$i];
echo "</td>";
}
else
{
echo "<td>";
echo "null";
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
or something like this:
<table id="working" border="0" cellspacing="1" cellpadding="3">
<tr>
<?php foreach ($csv->titles as $value): ?>
<td><?php echo $value; ?></td>
<?php endforeach; ?>
</tr>
<?php foreach ($csv->data as $key => $row): ?>
<tr>
<?php foreach ($row as $value): ?>
<td><?php echo $value; ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>
EDIT: Should this be a community wiki question?