Original Title Concept: Template Engine or Separating Data from Code?
I’ve heard about separating design elements from data, but what I am not so familiar with is separating code from html design. Let me give you an example of what I am looking at.
//Pseudo code based on real code
<div id="header">
<?php
if( $_SESSION['pop'] != ''){
//QUERY DATABASE FOR DATA (imagine an sql statement here)
//Results put into associative array - example data follows
$data['fullname'] = "Pat Benatar";
$data['status'] = "admin";
?>
<h1 class="agentname"><?php echo $data['fullname']; ?></h1>
<?php
switch ( $data['status'] ) ){
case 'admin':
$class = 'Administrator';
break;
case 'operator':
$class = 'Operator';
break;
case 'agent':
$class = 'Marketing Agent';
break;
default:
$class = '';
break;
}
?>
<?php }
else{ ?>
<h1>Login Required.</h1>
<?php } ?>
<p id="servertime"><?php echo date(r); ?></p>
<?php if(isset($class)){ ?>
<h2><?php echo $class; ?></h2>
<?php } ?>
</div>
I find this a bit unsightly and a bit harsh to look at when in essence the end result is simply this:
<div id="header">
<h1>Pat Benatar</h1>
<p>Fri, 24 Jun 2011 08:39:11</p>
<h2>Administrator</h2>
</div>
Do template engines make the html syntax look cleaner. Something like
<h1>{name}</h1>
Am I mistaken to call this concept ‘templating’ ?
How can I make my HTML code look cleaner?
I guess an equally valid question is that although I do both programming and coding, how would a web designer and a programmer work together without confusing each other with their respective syntax?