Seite 1 von 1

Template Funktion ich verzweifle noch!!!!!

Verfasst: 05.06.2004 00:24
von rox²³
Ich krieg ne Asche ich sitze nun seit fast einer Woche vor dem Problem.
Hab schon in unzähligen Foren um rat gefragt.

Ich bekomme einfach nicht zustande das die Templates richtig geparst werden.

index.php:

Code: Alles auswählen

<?
$tmpl_name = 'index.tpl';
$tmpl_content[title] = 'echo "blabla";
$gaga = 123 + 123;
echo $gaga;';
$tmpl_content[text] = 'echo "Hallo Welt";
$baba = 999 * 999;
echo $baba;';
require_once('./templates/class_template.php');
template ($tmpl_name, $tmpl_content);
echo $work;
?>
index.tpl:

Code: Alles auswählen

<html>
<head>
<title>%%title%%</title>
</head>
<body><center>%%text%%</center>
</body>
</html>
class_template.php:

Code: Alles auswählen

<? 
function template ($tmpl_name, $tmpl_content) {
$dir = 'c:\\intranet\\Apache2\\htdocs\\test\\templates';
  global $work;
      $pfad = "".$dir."\\".$tmpl_name."";
      $tmpl = file_get_contents($pfad);
      if ( trim($tmpl) != "" ) {
        $work = $tmpl;
        while ( list( $key, $val ) = each( $tmpl_content ) ) { 
			    $x = "%%" . strtolower($key) . "%%";
          $work = str_replace($x, "<?".$val."?>", $work);
          }
		  }
		return $work;
}
?>
Warum wird der php code nicht ausgeführt und statt dessen nur so angezeigt wie er in der index.php steht?

Ich hab auch schon eval() ausprobiert nix führt zum erfolg :cry:

Verfasst: 05.06.2004 00:48
von PhilippK
PHP-Code beginnt i.d.R. mit

Code: Alles auswählen

<?php
:D

Gruß, Philipp

Verfasst: 05.06.2004 00:56
von rox²³
Das heist jetzt?
Was muss ich ändern?
Sorry aber ich raff imoment nix mehr :-?

Re: Template Funktion ich verzweifle noch!!!!!

Verfasst: 05.06.2004 01:36
von Leuchte
index.php:
<?php
$tmpl_name = 'index.tpl';
$tmpl_content[title] = 'echo "blabla";
$gaga = 123 + 123;
echo $gaga;';
$tmpl_content[text] = 'echo "Hallo Welt";
$baba = 999 * 999;
echo $baba;';
require_once('./templates/class_template.php');
template ($tmpl_name, $tmpl_content);
echo $work;
?>
class_template.php:
<?php
function template ($tmpl_name, $tmpl_content) {
$dir = 'c:\\intranet\\Apache2\\htdocs\\test\\templates';
global $work;
$pfad = "".$dir."\\".$tmpl_name."";
$tmpl = file_get_contents($pfad);
if ( trim($tmpl) != "" ) {
$work = $tmpl;
while ( list( $key, $val ) = each( $tmpl_content ) ) {
$x = "%%" . strtolower($key) . "%%";
$work = str_replace($x, "<?".$val."?>", $work);
}
}
return $work;
}
?>

Verfasst: 05.06.2004 01:47
von rox²³
Ja das hab ich mal so übernommen aber ändert daran trotsdem nix. Es geht weder mit <? noch mit <?php.

Ich dachte eigentlich immer das ist es egal ist ob mit <? oder <?php.

P.S. Ich hab nen kleines einfaches Forum bestehend aus 34 Dateien die alle mit <? anfangen und das funzt auch prima.

P.P.S. Langsam denke ich es liegt an meinem Webserver :(

EDIT: Am Webserver liegts auch nicht habs getestet.

Verfasst: 05.06.2004 08:42
von Jensemann
rox²³ hat geschrieben: Ich dachte eigentlich immer das ist es egal ist ob mit <? oder <?php.
ist einstellungssache in der php.ini

Verfasst: 05.06.2004 13:01
von rox²³
Naja bei mir funktioniert beides auf dem Testwebserver sowohl auf dem Server des Hosters.

Aber wieso bekomme ich die Templates nicht odnungsgemäß ausgegeben?

Verfasst: 05.06.2004 13:13
von PhilippK
Weil's mir gerade auffällt:

Code: Alles auswählen

$tmpl_content[title] = 'echo "blabla"; 
sollte wohl

Code: Alles auswählen

$tmpl_content['title'] = 'blabla';
heißen (das gleiche ein paar Zeilen später nochmal) und

Code: Alles auswählen

template ($tmpl_name, $tmpl_content); 
echo $work; 
besser

Code: Alles auswählen

echo template ($tmpl_name, $tmpl_content);
Ich würde auch mal schauen, dass du dir lokal die PHP-Warnungen anzeigen lässt.

Gruß, Philipp

Verfasst: 05.06.2004 14:40
von rox²³
THX das funktioniert :grin:
Endlich ich dachte schon ich muss mir nen Strick nehmen ^^