I find doing this sort of thing quite ugly and somewhat "primitive":
PHP Code:
echo "\t\t<p";
if ($something) echo ' class="current"';
echo ">$text</p>\n";
or:
PHP Code:
if ($something) $c = ' class="current"';
echo "\t\t<p$c>$text</p>\n";
Doing this sort of thing with javascript is much nicer:
Code Javascript:
var p = document.createElement('p');
if (something) p.className = 'insect';
parent.appendChild(p);
It might be more verbose, but it's more readable and it's logical. Even if you're using templates, there must come a point where you have to go through the ugliness above (or something similar to it), so I wonder how MVC advocates deal with this. Do you use PHP's DOM extension? If not, then what do you do?
Bookmarks