7. <?php include_once 'PHPTAL/PHPTAL.php'; $phptal = new PHPTAL( 'markupfile.html' ); $phptal->set( 'PAGE_TITLE', 'PHPTAL - introduction'); $phptal->set( 'DATAGEN', new MyClass()); try { echo $phptal->execute(); } catch(Exception $e) { echo $e; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title tal:content=”PAGE_TITLE” ></title> </head> <body> <div tal:content=” php: DATAGEN.getContent() ” tal:condition=” php: DATAGEN->checkAccess() ”></div> </body> </html> <?php class MyClass { function checkAccess() { return true; } function getContent() { return “PHPTAL is simple!”; } } ?>
8. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title> PHPTAL - introduction </title> </head> <body> <div>PHPTAL is simple!</div> </body> </html>
9. <head metal:define-macro=”headerSection” > <title>PHPTAL - Macro</title> </head> <div metal:define-macro=”footerSection” > <p>Footer is not unless used.</p> </div> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head metal:use-macro=”Macro.html/headerSection” > <title>This will be over-written</title> </head> <body> <p> Head section is included via macro! </p> </body> </html> Macro.html
10. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title> PHPTAL - Macro </title> </head> <body> <p> Head section is included via macro! </p> </body> </html>