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

Template im Template Problem

 
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
Kidchaos
Smarty Rookie


Joined: 10 Sep 2004
Posts: 9
Location: Berlin

PostPosted: Fri Sep 10, 2004 12:30 pm    Post subject: Template im Template Problem Reply with quote

Hallo,

ich "arbeite" seit einigen Tagen mit Smarty. Habe mir auch das Manual durchgelesen und die Beispiele gemacht. NUn wollte ich zum Testen einmal eine einfache Seite erstellen. Aber irgendwie scheiter ich dort schon recht weit am anfang.

Ich habe eine index.tpl, header.tpl(wird per {include} in die index.tpl geladen) und eine footer.tpl (wird per {include} in die index.tpl geladen). Soweit auch alles kein Problem. Nun wollte ich die Sache ein wenig dynamischer gestallten und habe ein weiteres Template angelegt. news.tpl. Diese möchte ich an eine bestimmte stelle in meiner index.tpl Laden. Das funktioniert aber nur bedingt. Was heißt er läd zwar das news.tpl Template aber nicht dort wo ich es ihm gesagt habe sondern an den anfang meiner Datei. Folgend nun erstmal meine eizelnen Datein damit ihr auch sehen könnt wie ich vorgegangen bin.

index.php
[php:1:7700c8fade]<?php
include("libaries/config.inc.php");
require('libaries/setup.php');
include("libaries/class.mysql.inc.php");

$smarty = new Smarty_test;
$db = new mysql();
$db->connect($_mysql['host'], $_mysql['user'], $_mysql['password']);
$db->select_db($_mysql['database']);

unset($_mysql);

switch($_GET['site']) {
case "news":
default:
include("modules/news.inc.php");
break;

case "links":
include("modules/links.inc.php");
break;
}
$header = "<h1>Willkommen!!!</h1>";
$navigation = "Test<br><br>Test";


$smarty->assign("design", array("header" => $header,
"navigation" => $navigation,
"content" => $content,
"copyright" => $copyright));

$smarty->display('index.tpl');
?>[/php:1:7700c8fade]

index.tpl
Code:
{include file="header.tpl"}
<table width="75%" border="0" cellpadding="0" cellsapcing="0"  align="center">
  <tr>
     <td align="center">{$design.header}</td>
  </tr>
  <tr>
     <td width="40%">{$design.navigation}</td>
     <td width="60%">{$design.content}</td>
  </tr>
  <tr>
     <td colspan="2" align="center">{$design.copyright}</td>
  </tr>
</table>
{include file="footer.tpl"}


news.tpl
Code:
<table width="50%" border="1" cellpadding="0" cellspacing="2">
{foreach from=$inhalt item=news}
  <tr>
     <td>{$news.catid}</td>
     <td><b>{$news.titel}</b></td>
  </tr>
  <tr>
     <td colspan="2">{$news.text}</td>
  </tr>
  <tr>
     <td>Posted by {$news.userid} @ {$news.datum}</td>
     <td>X Kommentare</td>
  </tr>
  <tr>
     <td colspan="2">&</td>
  </tr>
{/foreach}
</table>


news.inc.php

[php:1:7700c8fade]<?php
$inhalt = array();
$query = $db->query("Select
id, catid, userid, titel, text, datum, poster
From
`news`
Order by datum DESC Limit 0,15");
while($row = $db->fetch_array($query)) {
$inhalt[] = $row;
}
$content = $smarty->assign("inhalt", $inhalt);

$content = $smarty->display('news/show.tpl');
?>[/php:1:7700c8fade]

Ich habe also in der index.php verschiedene Variablen definiert die dann in dem index.tpl Template verarbeitet werden sollen. Die variable $content lege ich aber in der news.inc.php fest. Wo meiner meinung nach wohl auch der Fehler liegt ich aber bisher keine andere Idee hatte das zu lösen. Ich hoffe das ihr mir dort ein wenig helfen könnt. Solltet ihr noch weitere Informationen brauchen könnt ich mich gerne Kontaktieren.

Viel Dank.
Back to top
View user's profile Send private message
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Fri Sep 10, 2004 1:00 pm    Post subject: Reply with quote

Anstatt von
[php:1:a5bd336bbc]
switch($_GET['site']) {
case "news":
default:
include("modules/news.inc.php");
break;

case "links":
include("modules/links.inc.php");
break;
}
[/php:1:a5bd336bbc]

mach besser so:

[php:1:a5bd336bbc]
if ( file_exists(( $file = 'modules/'. $_GET['site'] .'.inc.php'))) {
include( $file);
}
[/php:1:a5bd336bbc]

und sowas gibts nicht:
[php:1:a5bd336bbc]
$content = $smarty->assign("inhalt", $inhalt);
$content = $smarty->display('news/show.tpl');
[/php:1:a5bd336bbc]

Weder Assign() noch Display() geben werte zurück!
Ausserdem kann man nur einmal Display() aurufen !?
Sonst würdest du ja ein TPL einblenden und dann gleich mit dem nächsten überblenden....
Back to top
View user's profile Send private message
Kidchaos
Smarty Rookie


Joined: 10 Sep 2004
Posts: 9
Location: Berlin

PostPosted: Fri Sep 10, 2004 1:36 pm    Post subject: Reply with quote

Danke erstmal.

Das mit den 2 Displays ist ja mein Problem. Wie kann ich in dem Haupttemplate einen Bereich definieren in dem ein anderes Template(nachdem es geparst wurde, sprich variablen etc. ersetzt wurde), in diesem Falle show.tpl, geladen wird? Ich habe da auch schon das manual mehrmals durchgewältz und auch einige funktionen probiert aber bisher ohne Erfolg.
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Fri Sep 10, 2004 1:46 pm    Post subject: Reply with quote

erstmal statt:
[php:1:4d994d4f0b]
$content = $smarty->assign("inhalt", $inhalt);
$content = $smarty->display('news/show.tpl');
[/php:1:4d994d4f0b]

[php:1:4d994d4f0b]
$smarty->assign("inhalt", $inhalt);
$content = $smarty->fetch('news/show.tpl');
[/php:1:4d994d4f0b]

fetch() ist das pendant zu display(), nur dass es die template-ausgabe als string zurückliefert. das hättest du im manual finden können Wink


@kills: natürlich kann man so viele display() aufrufe in seinem script haben wie man will.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Kidchaos
Smarty Rookie


Joined: 10 Sep 2004
Posts: 9
Location: Berlin

PostPosted: Fri Sep 10, 2004 1:56 pm    Post subject: Reply with quote

Danke Danke Smile

Aber ich muss ehrlich sagen ich habe diese Variable bis zu deinem Post nie zuvor gesehen. Vieleicht auch einfach überlesen, da ich gestern den ganzen Tag über nur des Manual gelesen hatte. Aber nochmals Danke. Smile)
Back to top
View user's profile Send private message
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