Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [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
mdco
post
Post #2





Grupa: Zarejestrowani
Postów: 324
Pomógł: 5
Dołączył: 14.12.2004

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


Może tak:
  1. <?php
  2. $st -> addChange('{content}', file_get_contents('content.php') );
  3. ?>
Go to the top of the page
+Quote Post
pikey
post
Post #3





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

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


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>
Go to the top of the page
+Quote Post
gekon
post
Post #4





Grupa: Zarejestrowani
Postów: 614
Pomógł: 7
Dołączył: 10.11.2003
Skąd: Rzeszów/Kraków

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


A tak?
  1. <?php
  2. $st -> addChange('{content}', eval(file_get_contents('content.php')));
  3. ?>
Go to the top of the page
+Quote Post
tiraeth
post
Post #5





Grupa: Przyjaciele php.pl
Postów: 1 789
Pomógł: 41
Dołączył: 30.10.2003
Skąd: Wrocław

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


To może inaczej (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) Prze-eval-uj już cały szablon po kompilacji (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
pikey
post
Post #6





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

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


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

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

 



RSS Aktualny czas: 22.08.2025 - 13:30