Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Szablony tpl
sajborg
post 10.01.2005, 17:08:19
Post #1





Grupa: Zarejestrowani
Postów: 271
Pomógł: 0
Dołączył: 20.08.2003
Skąd: Szczecinek

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


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. ?>


--------------------
Warsztat: gPHPEdit | Linux 2.6.17-11-generic (Ubuntu)
Sprzęt: Noteook BenQ A33E
___________________________________________________
Go to the top of the page
+Quote Post
piwoszeq
post 14.01.2005, 23:11:11
Post #2





Grupa: Zarejestrowani
Postów: 57
Pomógł: 0
Dołączył: 13.01.2005
Skąd: warszawa

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


  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. ?>


Ten post edytował piwoszeq 14.01.2005, 23:13:06
Go to the top of the page
+Quote Post

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 Wersja Lo-Fi Aktualny czas: 14.08.2025 - 15:02