Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Szablony tpl
Forum PHP.pl > Forum > PHP
sajborg
Witam Mam taki kodzik zaczerpnięty z strefaphp.net

  1. <?php
  2. function parse()
  3. {
  4.  $i=0;
  5.  foreach ($this->unparsed as $template)
  6.  {
  7. $found = array();
  8. if(preg_match_all(&#092;"#{(.+?)}#is\", $template, $found))
  9. {
  10.  foreach($found[1] as $block)
  11.  {
  12. $block_name = '{'.$block.'}';
  13. $block_values = $this -> blocks[$i][$block];
  14. $template = str_replace($block_name, $block_values, $template);
  15.  }
  16. }
  17. if (preg_match_all('#<BEGIN (.*?)>#is', $template, $found)) {
  18. }
  19. $this -> parsed[] = $template;
  20. $i++;
  21.  }
  22. } #end function parse()
  23.  
  24. ?>


Jak przerobic to zeby działała na wstawkach zrobiłem takie waruneczek
Kod
if (preg_match_all('#<BEGIN (.*?)>#is', $template, $found)) {
}

ale nie wiem co wstawic

Wywoływanie bedzie sie odbywało

  1. <?php
  2. while(.....){
  3. $tempaltes->//powinna byc funcka asssing_block wrzucająca zmienione bloki subselekcji do tabli
  4. assing_block('nazwa zubselekcji', array('zmienna'=>$bele['dasad']));
  5. //Ale nie wiem jak to napisc
  6. }
  7. $tempaltes->parse();
  8. ?>
piwoszeq
  1. <?
  2. /*
  3. * engine.php
  4. */
  5.  
  6. class HtmlTemplate 
  7.  
  8. {
  9. var $template;
  10. var $html;
  11. var $parameters = array();
  12.  
  13. function HtmlTemplate ($template)
  14. {
  15. $this->template = $template;
  16. $this->html = implode(&#092;"\", (file($this->template)));
  17. }
  18. function SetParameter ($variable, $value)
  19. {
  20. $this->parameters[$variable] = $value;
  21. }
  22. function CreatePage ()
  23. {
  24. foreach ($this->parameters as $key => $value) 
  25. {
  26. $template_name = '<!--{' . $key . '}-->';
  27. $this->html = str_replace ($template_name, $value, $this->html);
  28. }
  29. echo $this->html;
  30. }
  31. }
  32.  
  33. ?>


  1. <?
  2. require_once (&#092;"engine.php\"); // Wczytuje twój engine :)
  3.  
  4. $page = new HtmlTemplate (&#092;"templates/body.html\"); // Twoje templates tongue.gif
  5. $page-> SetParameter(&#092;"TITLE\", \"Jakiś text\");
  6.  
  7. $page-> CreatePage();
  8. unset ($page);
  9. ?>
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.