login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Overige scripts > Template parser (klein)

Template parser (klein)

Auteur: XenoX - 19 augustus 2004 - 17:06 - Gekeurd door: Dennisvb - Hits: 4147 - Aantal punten: 2.50 (2 stemmen)




Dit script heeft de basis functies van een template parser zoals:
- Wissellen
- Bestanden invoegen

Later komt er een uitgebreide versie met:
- Blocks
- ...
(Als je nog wat weet PM me)

Code:
class.xtemplate.php
  1. <?php
  2. class xtemplate {
  3. var $bestand;
  4. var $invoeg;
  5.  
  6. function __error($functie, $error) {
  7. echo "<hr><b>Fout bij functie:</b> ".$functie;
  8. echo "<hr><b>De fout:</b> ".$error."<hr>";
  9. }
  10.  
  11. function leesbestand($bestand) {
  12. if(!file_exists($bestand)) {
  13. exit($this->__error("leesbestand", $bestand." bestaat niet!"));
  14. } else {
  15. include($bestand);
  16. $this->bestand = ob_get_contents();
  17. }
  18. }
  19.  
  20. function wissel($vind, $vervang) {
  21. if(empty($this->bestand)) {
  22. exit($this->__error("wissel", "Je moet eerst de functie leesbestand() uitvoeren!"));
  23. } else {
  24. $this->bestand = str_replace("{".$vind."}", $vervang, $this->bestand);
  25. }
  26. }
  27.  
  28. function invoegen($bestand) {
  29. if(!file_exists($bestand)) {
  30. exit($this->__error("invoegen", $bestand." bestaat niet!"));
  31. } else {
  32. include($bestand);
  33. $this->invoeg = ob_get_contents();
  34.  
  35. $this->bestand = str_replace("[".$bestand."]", $this->invoeg, $this->bestand);
  36. }
  37. }
  38.  
  39. function laatzien() {
  40. if(empty($this->bestand)) {
  41. exit($this->__error("laatzien", "Je moet eerst de functie leesbestand() uitvoeren!"));
  42. } else {
  43. echo $this->bestand;
  44. }
  45. }
  46. }
  47. $xtemplate = new xtemplate;
  48. ?>


voorbeeld:
  1. <?php
  2. include("class.xtemplate.php");
  3.  
  4. $xtemplate->leesbestand("bestand.tpl");
  5.  
  6. $xtemplate->wissel("titel", "Test Pagina");
  7.  
  8. $xtemplate->invoegen("test.php");
  9.  
  10. $xtemplate->laatzien();
  11. ?>


bestand.tpl
  1. <html>
  2.  
  3. <head>
  4. <title>{titel}</title>
  5. </head>
  6.  
  7. <body>
  8.  
  9. [test.php]
  10.  
  11. </body>
  12.  
  13. </html>


test.php:
  1. Dit is een pagina...
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (3)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.044s