Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php + html] Problem z templatkami
Forum PHP.pl > Forum > Przedszkole
Yazzie
Mam takie oto kody.

index.php

  1. <?php
  2. include ("db_config.php");
  3. include ("includes/functions.php");
  4.  
  5. $template = new template (); 
  6.  
  7. $template-> add_file("header.tpl");
  8. $template-> add_file("index.tpl");
  9. $template-> add_file("footer.tpl");
  10.  
  11. @include ("language/polish/main.php");
  12.  
  13. $template-> set_template(array(
  14. "LANG_POWERED_INFO" => $lang['powered_info'],
  15. "LANG_WELCOME" => $lang['welcome'],
  16. "LANG_KEYPORTAL_VERSION" => $lang['keyportal_version'],
  17. "LANG_DOWNLOAD_KEYPORTAL" => $lang['download_keyportal'],
  18. ));
  19. ?>


language.php

  1. <?php
  2. $lang['powered_info'] = 'Portal oparty o skrypt KeyPortal';
  3. $lang['welcome'] = 'Witamy na stronie';
  4. $lang['keyportal_version'] = 'v1.0.0';
  5. $lang['download_keyportal'] = 'Pobierz KeyPortal';
  6. ?>


functions.php

  1. <?php
  2. class template
  3. {
  4. var $theme = 'Default';
  5. var $assigned_vars = array();
  6. var $template_content = '';
  7.  
  8. function __construct() {}
  9.  
  10. function error ($message)
  11. {
  12. echo $message;
  13. }
  14.  
  15. function add_file ($template_file)
  16. {
  17. $template_path = "templates/$this->theme/$template_file";
  18.  
  19. if( file_exists ($template_path) )
  20. {
  21. $this->template_content = file_get_contents ($template_path);
  22. unset ($template_path);
  23. }
  24. else
  25. {
  26. error ("Szablon $template_file nie może zostać odnaleziony");
  27. }
  28. } 
  29.  
  30. function set_template () 
  31. {
  32. foreach ( $this->assigned_vars as $key => $value )
  33. {
  34. $this->assigned_vars[strtoupper($key)] = $value;
  35. }
  36. }
  37.  
  38. function __destruct ()
  39. {
  40. foreach ( $this->assigned_vars as $key => $value )
  41. {
  42. $this->template_content = str_replace('{'.$key.'}', $value, $this->template_content);
  43. }
  44.  
  45. echo $this->template_content;
  46. }
  47. }
  48. ?>


I mam z tym taki problem, że gdy wchodzę na stronę nie wyświetla mi templatek zainicjowanych w pliku index.php. Co mam źle?
nexis
Skrypt zwraca jakiś błąd? Np. "Szablon nie może zostać odnaleziony"?
Yazzie
Nie, po prostu pokazuje się czysta strona.
nexis
System szablonów działa prawidłowo. Upewnij się, że Twoje szablony znajdują w następującej lokalizacji:

templates/Default/header.tpl
templates/Default/index.tpl
templates/Default/footer.tpl
Yazzie
No znajdują się :| Nie wiem już, co mam robić sad.gif
nexis
Musisz gdzieś robić głupi błąd, bo u mnie wszystko ładnie działa.
Yazzie
W tym problem, że wszystko (chyba) jest OK sad.gif
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.