Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php] system szablonó - problem
Forum PHP.pl > Forum > PHP
pikey
mam taki system szablonów:
  1. <?php
  2.  
  3. class simpleTemplate {
  4.  
  5. var $toChange;
  6. var $str;
  7.  
  8. function simpleTemplate()
  9. {
  10. $this -> toChange = array();
  11. $this -> str = '';
  12. }
  13.  
  14. function setTemplate($ATemplate)
  15. {
  16. $this -> str = $ATemplate;
  17. }
  18.  
  19. function loadFromFile($AFileName)
  20. {
  21. $this -> str = file_get_contents($AFileName);
  22. }
  23.  
  24. function addChange($AKey, $AValue)
  25. {
  26. $this -> toChange[$AKey] = $AValue;
  27. }
  28.  
  29. function executeChanges()
  30. {
  31. if (count($this -> toChange) > 0) {
  32. $tmpKeys = array_keys($this -> toChange);
  33.  
  34. foreach ($tmpKeys as $currentKey) {
  35. $this -> str = str_replace($currentKey,
  36.  $this -> toChange[$currentKey],
  37.  $this -> str);
  38. }
  39. }
  40. return $this -> str;  
  41.  
  42. }
  43.  
  44. }
  45.  
  46. ?>


szablon.tpl:

  1. <title>{title}</title>
  2. </head>
  3. {content}
  4. </body>
  5. </html>


index.php:

  1. <?php
  2. nclude_once('parser.php');
  3. $st = new simpleTemplate();
  4. $st -> loadFromFile('szablon.tpl');
  5. $st -> addChange('{title}', "Tytuł");
  6. $st -> addChange('{content}', "INCLUDOWANIE");
  7. echo $st -> executeChanges();
  8. ?>


własciwie wszystko jest ok tylko mam problem jezeli tam gdzie mam {content} chciałbym zaincludować plik (zeby zamiast {content} pojawiło sie <? include("content.php"); ?>
mdco
Może tak:
  1. <?php
  2. $st -> addChange('{content}', file_get_contents('content.php') );
  3. ?>
pikey
Cytat(mdco @ 1.11.2006, 18:36:02 ) *
Może tak:
  1. <?php
  2. $st -> addChange('{content}', file_get_contents('content.php') );
  3. ?>


strona jest pusta a to jest żrodlo tego co sie pokazuje:
Cytat
<html>
<head>
<title>Tytuł</title>
</head>
<body>
<?php
echo "tresc pliku content.php";
?>
</body>
</html>
gekon
A tak?
  1. <?php
  2. $st -> addChange('{content}', eval(file_get_contents('content.php')));
  3. ?>
tiraeth
To może inaczej smile.gif Prze-eval-uj już cały szablon po kompilacji smile.gif
pikey
Cytat(gekon @ 2.11.2006, 15:21:43 ) *
A tak?
  1. <?php
  2. $st -> addChange('{content}', eval(file_get_contents('content.php')));
  3. ?>


wszystko byłoby dobrze gdyby tylko tekst z content.php nie pojawiał sie tam gdzie to jest pokazane:

Kod
tresc pliku content.php1 2 3 4 5 6 7 8 9 10 <br>lol<html>
<head>
<title>Hehe :)</title>
</head>
<body>

</body>
</html>
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.