Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem z wyświetlaniem
Forum PHP.pl > Forum > PHP
Gibcio2008
Plik przed sparsowaniem z rozszerzeniem TPL
  1. <!DOCTYPE html>
  2. <title>{title}</title>
  3. </head>
  4. [if $a==1]{title}[/if][else]Brak[/else]
  5. </body>
  6. </html>



Plik po sparsowaniu z rozszerzeniem PHP
  1. <!DOCTYPE html>
  2. <head>
  3. <title>Tytuł</title>
  4. </head>
  5. <body>
  6. <?php if ($a==1) { echo "Tytuł"; } else { echo "Brak"; } ?>
  7. </body>
  8. </html>


Teraz mam pytanie czemu to nie działa, tzn. nic oprócz Tytułu w tagu <title></title> się nie wyświetla ?

Kod Parsera
  1. <?php
  2.  
  3. class Template
  4. {
  5. var $TemplateDir = "themes/default";
  6. var $CacheDir = "cache";
  7.  
  8. var $code = array
  9. (
  10. "#\[b\](.*?)\[/b\]#" => "<strong>\\1</strong>",
  11. "#\[if (.*?)\](.*?)\[/if\]#" => "<?php if (\\1) { echo \"\\2\"; } ?>"
  12. );
  13.  
  14. function Template($filename)
  15. {
  16. $this->baseDir = $this->TemplateDir;
  17. $this->cacheDir = $this->CacheDir;
  18.  
  19. $this->fileTemplateExt = $filename.".tpl";
  20. $this->fileCacheExt = $filename.".php";
  21.  
  22. $this->fileTemplate = $this->baseDir."/".$this->fileTemplateExt;
  23. $this->fileCache = $this->cacheDir."/".$this->fileCacheExt;
  24. }
  25.  
  26.  
  27. function LoadTemplate()
  28. {
  29. if(!file_exists($this->fileTemplate))
  30. {
  31. die("File not found: ".$this->fileTemplate." !");
  32. }
  33.  
  34. $this->template = file_get_contents($this->fileTemplate);
  35.  
  36. foreach($this->code as $source => $destination)
  37. {
  38. $this->template = preg_replace($source, $destination, $this->template);
  39. }
  40. }
  41.  
  42. function Replacer($name, $value)
  43. {
  44. $this->template = str_replace("{".$name."}", $value, $this->template);
  45. }
  46.  
  47.  
  48. function Show()
  49. {
  50. if(!$this->Exists())
  51. {
  52. $this->Save($this->template);
  53. return $this->Load();
  54. }
  55. else
  56. {
  57. return $this->Load();
  58. }
  59. }
  60.  
  61. function Exists()
  62. {
  63. return file_exists($this->fileCache);
  64. }
  65.  
  66. function Save($data)
  67. {
  68. $fp = fopen($this->fileCache, "w");
  69. fputs($fp, $data);
  70. fclose($fp);
  71. }
  72.  
  73. function Load()
  74. {
  75. return file_get_contents($this->fileCache);
  76. }
  77. }
  78.  
  79.  
  80. ?>
Janusz1200
A jaką wartość ma zmienna $a? A jest ustawiona? A zdebugowałeś? A w templatkach zwykle jest $this->a i templatka jest parsowana przez jakieś view, z której bierze obiekty przez to $this.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.