I’m making a simple template system. It’s annoying to not to be able to keep the code in the PHP file and output it in html file… Its not nice to have this in the template:
<?php while ($row = mysql_fetch_array($query)) { $name = $row['forum_name']; $date = $row['forum_date']; $desc = $row['forum_description']; $lastpost = $row['forum_lastpost']; ?> <h1><?php echo $name ?></h1> <p><?php echo $desc ?></p> <?php } ?>
Is there some way I could keep the code in the PHP file?
Thanks
I would suggest doing the query and processing in the php file, not in the template. Build an array in the php file, then let the template display it.
This is how I typically do it:
PHP file:
Template file:
An alternative syntax is using ‘endwhile’ as glavić showed: