Mam problem z parserem szablonów. Polega on na tym że includowany plik pojawia się na samej górze strony, a nie w miejscu gdzie chce. Próbowałem też pisac własne funkcje includujące pliki, ale wtedy nie moge przekazac do includowanego pliku zmiennej z $_GET'a czy innej tablicy superglobalnej. (Poprostu nie wyświetla mi wartości zmiennej $xp przekazanej przez pasek adresu # http://localhost/?url=inc.php&xp=JakasZmienna #) Mam również problem z utworzeniem subsekcji. Czy moglibyście w jakiś sposób nakierować mnie na jakieś konkretne rozwiązania?? (przykłady i adaptacje załączonej klasy mile widziane :) ) Z góry dziękuje!


index.tpl


  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  4. <title>Template : {TYTUL}</title>
  5. </head>
  6. <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  7. <tr>
  8. <td align="center" valign="top">
  9. <table width="700" border="0" cellpadding="4" cellspacing="10">
  10. <tr>
  11. <td colspan="3" id="table"><div align="right">{LOGO}</div></td>
  12. </tr>
  13. <tr>
  14. <td width="20%" valign="top" id="table">{MENU1}</td>
  15. <td width="60%" height="300" valign="top" id="table">{TRESC}</td>
  16. <td height="20%" valign="top" id="table">{MENU2}</td>
  17. </tr>
  18. <tr>
  19. <td colspan="3" align="center" id="table">{STOPKA}<br><b>{CZAS}</b></td>
  20. </tr>
  21. </table></td>
  22. </tr>
  23. </body>
  24. </html>







template.class.php


  1. <?php
  2. class TemplateSTCMS {
  3.  
  4.  public $TemplateSTCMS;
  5.  public $DaneSTCMS;
  6.  public $ParsedSTCMS;
  7.  
  8.  
  9.  public function __construct( $name ){
  10.  if(isset( $name ) && !empty( $name )){
  11.  if(file_exists( $name )){
  12.  $this -> TemplateSTCMS = implode( '', file( $name ) );
  13.  }else{
  14.  echo&#092;"Plik szablonu <b>$name</b> nie instieje\";
  15.  exit;
  16.  }
  17.  }else{
  18.  echo &#092;"Nie podano nazwy szablonu!\";
  19.  exit;
  20.  }
  21.  }
  22.  
  23.  
  24.  public function parse( ){
  25.  return $this -> ParsedSTCMS = preg_replace('/{([^}]+)}/e', '$this -> DaneSTCMS[\"1\"]', $this -> TemplateSTCMS);
  26.  }
  27.  
  28.  
  29.  public function show( ){
  30.  print $this -> ParsedSTCMS;
  31.  }
  32.  
  33.  
  34.  public function destruct__( ) {
  35.  unset( $this -> DaneSTCMS );
  36.  unset( $this -> TemplateSTCMS );
  37.  unset( $this -> ParsedSTCMS );
  38.  }
  39.  
  40. }
  41.  
  42. ?>








test.php


  1. <?php
  2. include'template.class.php';
  3.  
  4. $tSTCMS = new TemplateSTCMS( 'index.tpl' );
  5. $tSTCMS -> DaneSTCMS = array(
  6.  'TYTUL' => 'tytul strony',
  7.  'TRESC' => 'srodek strony',
  8.  'MENU1' => 'menu 1 menu 1 menu 1',
  9.  'MENU2' => include &#092;"$url\",
  10.  'STOPKA' => 'stopka stopka stopka',
  11.  'LOGO' => 'Bla bla bla'
  12.  );
  13. $tSTCMS -> parse();
  14. $tSTCMS -> show();
  15. $tSTCMS -> destruct__();
  16.  
  17. ?>







inc.php


  1. <?php
  2. echo &#092;"$xp\";
  3. echo &#092;"test\";
  4. ?>