Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] system szablonó - problem
pikey
post
Post #1





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 15.10.2006

Ostrzeżenie: (0%)
-----


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"); ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.08.2025 - 22:17