Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Inhalte werden nicht angezeigt - wo liegt mein Fehler?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
Eistee
Smarty Rookie


Joined: 18 Jun 2004
Posts: 10

PostPosted: Tue Jul 13, 2004 9:41 am    Post subject: Inhalte werden nicht angezeigt - wo liegt mein Fehler? Reply with quote

Hi,
ich versuche grad meine site auf smarty umzubauen.
Im moment komm ich aber absolut nicht weiter Confused
Mein hp soll aus folgenden Templates bestehen:

1 header.html (Logo, Navigation etc.)
1 body.html (hier werden die Inhalte reingeladen)

Unter der Navigation in der header.html, an der Stelle, der später die Inhalte angezeigt werden sollen, steht als Platzhalter die Variable {$body}
In der body.html befindet sich an der Stelle, an der die tatsächlichen Inhalte angezeigt werden sollen die Platzhaltervariable {$ct}

Nun habe ich eine index.php in der sich der PHP/Smarty-Kram befindet, die sieht wie folgt aus:
[php:1:e12710ae42]
<?php
define('SMARTY_DIR', '/is/htdocs/47449/www.alkbrueder.de/smarty_alkbrueder/smarty/');

require(SMARTY_DIR.'Smarty.class.php');

$tpl_body = new smarty();
$tpl_ct = new smarty();
$tpl = new smarty();

$tpl->assign_by_ref('body', $tpl_body->fetch('templates/body.html'));

include('thwbnews.php');
$tpl->assign_by_ref('ct', $tpl_ct->fetch('templates/newsrow.html'));

$tpl->display('templates/header.html');
?>
[/php:1:e12710ae42]
(In der thwbnews.php werden lediglich Inhalte in ein array geschrieben, die später durch die newsrow.html ausgegeben werden sollen)

Wenn ich die index.php nun aufrufe, werden mir zwar sowohl header als auch body angezeigt, die eigentlichen Inhalte (das Template newsrow.html) fehlen aber Sad
Das sieht dann so auch:
http://www.alkbrueder.de/smarty_alkbrueder/
(alles unterhalb der Navigation ist der body)

Wenn ich nun die letzte zeile im PHP-Code abändere
-------------------------------------------------------------------------------------
$tpl->display('templates/body.html');
-------------------------------------------------------------------------------------
so werden mir alle Inhalte angezeigt, lediglich der header fehlt natürlich.

Wo liegt mein Fehler?
Habe ich etwas wichtiges übersehen?
Wie kann ich den Fehler beheben?

Ich bin für jede Hilfe dankbar.
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Jul 13, 2004 11:09 am    Post subject: Reply with quote

wenn du display("header.tpl") ausführst, wird auch nur header.tpl ausgegeben.

ich denke du willst eine index.tpl ausgeben, die so aussieht:

index.tpl
Code:

{include file="header.tpl"}
{include file="body.tpl"}



ausserdem musst du nicht jedes untertemplate mit fetch() in eine variable lesen und assignen. du kannst genausogut {include} nehmen.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Eistee
Smarty Rookie


Joined: 18 Jun 2004
Posts: 10

PostPosted: Tue Jul 13, 2004 11:54 am    Post subject: Reply with quote

Danke, jetzt funktionierts Smile
eine Frage hab ich aber noch?
Wie bekomme ich auch die Variable $tpl_ct aus meinem Code, du meinst ja, das dieses fetch nicht nötig sei:
So schaut die index.php nun aus:
[php:1:46b924055d]
<?php
define('SMARTY_DIR', '/is/htdocs/47449/www.alkbrueder.de/smarty_alkbrueder/smarty/');

require(SMARTY_DIR.'Smarty.class.php');

$tpl_ct = new smarty();
$tpl = new smarty();

include('thwbnews.php');
$tpl->assign_by_ref('ct', $tpl_ct->fetch('templates/newsrow.html'));

$tpl->display('templates/index.html');
?>
[/php:1:46b924055d]
Und so die neu erstellte index.html
Code:

{include file="header.html"}
{include file="body.html"}
{include file="footer.html"}

aus Designtechnischen Gründen musste ich auch eine neue footer.html erstellen.

Lässt sich an der jetzigen Aufteilung noch etwas verbesen, oder ist das soweit jetzt für meine Zwecke optimal?
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Jul 13, 2004 12:19 pm    Post subject: Reply with quote

du kannst den template-namen assignen, statt der ausgabe:

im php:
$smarty->assign('content_tpl', 'templates/newsrow.html');
// für andere seiten wird ein anderes template angegeben

im template body.tpl dann
Code:
... {include file=$content_tpl} ....


so mach ich das meistens.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP