DynaHTML - semi-dynamic webpages using php



Welcome to the DynaHTML homepage! Please select the desired topic:


Example

In the following, an include file named “template.inc.php” is created in which frequently used design elements are defined:

<?php
function InsertPageHeader($title) {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title><?php echo $title; ?></title>
  <link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>
<body>
  <h1><?php echo $title; ?></h1>
<?php
}

function InsertEMail($email) {
  switch ($email) {
    case 'dh': echo '<a href="mailto:henrici@informatik.uni-kl.de">Dirk Henrici</a>'; break;
    case 'br': echo '<a href="mailto:reuther@informatik.uni-kl.de">Bernd Reuther</a>'; break;
    default: echo '<a href="mailto:'. $email. '">'. $email. '</a>';
  }
}
?>

Note that all the flexibility of the php language can be accessed here, thus providing unlimited possibilities!

A new html-file is created:

<!--php_end-->
<!--php
  require_once('layout.inc.php');
  InsertPageHeader('This is the page title');
-->
[Additional content may be added here later on with an arbitrary WYSIWYG-editor]
In case you have further questions, please do not hesitate to contact
<!--php InsertEMail('dh'); echo ' or '; InsertEMail('br'); -->
</body>
</html>

Remark:

This html-file is in this stage not editable with an WYSIWYG-html-editor since important elements like the head of the html-file are missing. This would be the same if we used 'normal' php-tags here.
But after the first run of the utility the html-file is complete and therewith a drawback of offline-generated files addressed.

After utility execution the html-file looks like the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>This is the page title</title>
  <link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>
<body>
  <h1>This is the page title</h1>
<!--php_end-->
<!--php
  require_once('layout.inc.php');
  InsertPageHeader('This is the page title');
-->
[Additional content may be added here later on with an arbitrary WYSIWYG-editor]
In case you have further questions, please do not hesitate to contact
<!--php InsertEMail('dh'); echo ' or '; InsertEMail('br'); -->
<!--php_begin-->
<a href="mailto:henrici@informatik.uni-kl.de">Dirk Henrici</a> or <a href="mailto:reuther@informatik.uni-kl.de">Bernd Reuther</a>
<!--php_end-->
</body>
</html>

In this stage the file is completely html-conform!
Thus the file can be edited in an arbitrary WYSIWYG-html-editor now.

Only the content created by the php-code should not be changed directly, because the changes would get overwritten with the next pass of the utility
A preview of the page is possible offline in any browser as long as no additional webserver interpreted script code is used (like "<?php ... ?>").

If the php-include-file, in which the recurring page elements are defined, changes, the content of the html-file can be updated easily by running the utility again.

Remark about a special case in the example:

Normally, the script output is written into the html-file by the utility after a "<!--php command(); -->"-definition. This behaviour is changed in the case that the head of an html-file shall be created by php-code (like in the example): On order that declarations like "DOCTYPE" etc. are located at the beginning of the file, an initial "<!--php_begin -->" is then omitted and the php-code is defined after the "<!--php_end-->".