Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem z funkcją set_template
Forum PHP.pl > Forum > PHP
Yazzie
Witam

Oto moje pliki:

class/template_class.php
  1. <?php
  2. class template
  3. {
  4. var $theme = 'Default';
  5. var $assigned_vars = array();
  6. var $template_content = '';
  7. var $block_vars = array();
  8. var $template_html = NULL;
  9.  
  10. function add_file ($template_file)
  11. {
  12. $template_path = "./templates/$this->theme/$template_file";
  13.  
  14. if (file_exists($template_path))
  15. {
  16. $this->template_content = file_get_contents($template_path);
  17. }
  18. else
  19. {
  20. echo ("[ <b>Template</b> ] :: Szablon $template_path nie może zostać odnaleziony<br>");
  21. }
  22. }
  23.  
  24. function set_block_template ($block_name, $array)
  25. {
  26. if ( is_array($array) )
  27. {
  28. $temp_array = array();
  29. $block_count = 0;
  30.  
  31. foreach ($array as $key => $value)
  32. {
  33. $temp_array[$key] = $value;
  34. $block_count++;
  35. }
  36. $this->block_name[$block_name][] = $temp_array;
  37. }
  38. else
  39. {
  40. echo ("[ <b>Template</b> ] :: Dane przekazane funkcją <b>assign_block</b> nie są tablicą");
  41. }
  42. }
  43.  
  44. function set_template ($array)
  45. {
  46. foreach ($array as $key => $value)
  47. {
  48. $this->assigned_vars[strtoupper($key)] = $value;
  49. }
  50.  
  51. foreach ($this->assigned_vars as $key => $value)
  52. {
  53. $this->assigned_vars = str_replace('{'.$key.'}', $value, $this->assigned_vars);
  54. }
  55.  
  56. echo $this->template_content;
  57. }
  58. ?>


index.php

  1. <?php
  2. $template = new template;
  3.  
  4. $template-> add_file("header.tpl");
  5. $template-> add_file("index.tpl");
  6. $template-> add_file("footer.tpl");
  7.  
  8. $user['lang'] = 'polish';
  9.  
  10. include ($keybb_path . "language/" . $user['lang'] . ".php");
  11.  
  12. $template-> set_template(array(
  13. "L_POWERED_INFO" => $lang['powered_info'],
  14. "ALL_POSTS" => $result_1,
  15. ));
  16. ?>


header.tpl

  1. <title>{BOARD_TITLE} - ( {L_POWERED_INFO} )</title>
  2. </head>
  3.  
  4. </body>
  5. </html>


Zamiast napisu {L_POWERED_INFO} powinno pojawiać się na stronie Strona oparta o skrypt, jednak tak się nie dzieje. Próbuję to rozgryźć kilka dni i nadal nic sad.gif

Pomocy
Kicok
Cytat
  1. <?php
  2.  
  3. foreach ($this->assigned_vars as $key => $value)
  4. {
  5. $this->assigned_vars = str_replace('{'.$key.'}', $value, $this->assigned_vars);
  6. }
  7.  
  8. ?>


Na pewno masz tutaj zmieniać $this->assigned_vars? A nie czasem $this->template_content ? ;]
Yazzie
Dzięki, teraz działa, no głupi błąd, jak mogłem tego nie zauważyć biggrin.gif

Dzięki jeszcze raz tongue.gif

Okazuje się, że mam jeszcze jeden błąd. Nie wiem czemu, ale pokazuje tylko jeden plik template, choć w index.php są zakotwiczone 3. Co jest nie tak?
abc667
  1. <?php
  2. $this->template_content .= file_get_contents($template_path);
  3. ?>


np. ?
Yazzie
Dzięki, teraz wszystko pięknie gra, thx.
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.