Zum Inhalt springen

Extension mit Templatefile

Erstellt am 14. September 2006 · 4 Antworten · letzte Antwort am 14. September 2006

Tags: Frage

tobias_sa84 ·

Hallo zusammen,

habe folgendes Problem

habe eine Extension die mir eine Preistabelle aus der DB erstellen soll, jedoch gelingt mir das ersetzen mit Markern in dem Template file nicht so recht.

Also habe zwei schleifen:

//diese holt die Preiskategorien aus der DB
while(row1=mysql_fetch_array($res1)){
  $kategory=$row1['kategorie'];
  $kategory_beschreibung=$row1['beschreibung']; 
  //dies holt mir die dazugehörigen Preisnamen und Preise
  while(row2=mysql_fetch_array($res2)){
    $preisname=$row2['preisname'];
    $preis=$row2['preis'];
  }
}

Die Ausgabe soll über ein Template laufen und wie folgt aussehen:

<table>
   <tr><td> Kategoriename1 </td></tr>
   <tr><td> Kategoriepreis11 = preis11 </td></tr>
   <tr><td> Kategoriepreis12 = preis12 </td></tr>
   <tr><td> Kategoriepreis13 = preis13 </td></tr>
   <tr><td> Kategoriename2 </td></tr>
   <tr><td> Kategoriepreis21 = preis21 </td></tr>
   <tr><td> Kategoriepreis22 = preis22 </td></tr>
   <tr><td> Kategoriepreis23 = preis23 </td></tr>
</table>

Mein Problem liegt beim ersetzen der Marker im Template mit dem Inhalt.

Also ich bekomme immer wieder die das gesamte Template aus gegeben. Kann mir da wer helfen?

Danke schon einmal !

Gruß

Tobias

tobias_sa84 ·

Also vielen Dank für die Hilfe, aber auf der Seite war ich schon, die hat mir nicht geholfen.

hier mein Template:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Unbenanntes Dokument</title>
</head>

<body>
<!-- ###DOCUMENT_BODY### -->
	<table width="300">
	<!-- ###PREIS_LISTE### BEGINN -->
		<tr>
			<td colspan="3">###CATEGORY###</td>
		</tr>
		<tr>
			
			<!-- ###PREISE### BEGINN-->
			<td>###PREIS_NAME###</td><td>=</td><td>###PREIS###</td>
			<!-- ###PREISE### ENDW-->
		</tr>
		<tr>	
			<td colspan="3">###INFO###</td>
		</tr>
	<!-- ###PREIS_LISTE### ENDE -->	
<!-- ###DOCUMENT_BODY### -->
</body>
</html>

kann mir nicht wer da auf die Sprünge helfen, also bei mir wirde die kategorie bei jedem eintrag wieder mit ausgebegen

hier der php code

    $this->templateCode= $this->cObj->fileResource($conf["tmpl"]);
    $template = array();
    $template['total'] = $this->cObj->getSubpart($this->templateCode,'###DOCUMENT_BODY###');
    $template['item'] = $this->cObj->getSubpart($template['total'],'###PREIS_LISTE###');
  $result=$GLOBALS["TYPO3_DB"]->exec_SELECTquery("*","tx_tspricelist_category"," deleted = 0 AND hidden = 0"); 
  while($row=mysql_fetch_array($result)){
     $markerArray['###CATEGORY###'] = $row['category'];
     $markerArray['###INFO###'] = $row['info'];
  $result2=$GLOBALS["TYPO3_DB"]->exec_SELECTquery("*","tx_tspricelist_prices","category='".$row['uid']."' AND deleted = 0 AND hidden = 0");
     while($row2=mysql_fetch_array($result2)){
         $markerArray['###PREIS_NAME###']=$row2['pricename'];
         $markerArray['###PREIS###']=$row2['price'];
	 $content_item .= $this->cObj->substituteMarkerArrayCached($template["item"], $markerArray, array(), array());
    }
   $subpartArray['###PREIS_LISTE###'] = $content_item; 
  }
		
$content = $this->cObj->substituteMarkerArrayCached($template['total'], $markerArray, $subpartArray, $wrappedSubpartContentArray);
just2b ·

Habs mir jetzt nicht angeschaut, geb ich ehrlich zu, weils manchmal die nadel im Heuhaufen ist, hier ein funktionierender Code:

    $markerArray = array();
    $wrappedSubpartArray = array();
		$template = array();
		$template["total"] = $this->cObj->getSubpart($this->templateCode,"###LIST_TEMPLATE###");
		$template["item"] = $this->cObj->getSubpart($template["total"],"###ITEM_SINGLE###");		
		
		//prepare query
		$fields = 'uid, title, image';
		$tables = 'tx_rgthumbs_image';

		$temp_where='pid IN ('.$this->conf['source'].') AND hidden=0 AND deleted=0';
		$res = $TYPO3_DB->exec_SELECTquery($fields, $tables, $temp_where,'', '','');
  
    // generating list
		while($row = $TYPO3_DB->sql_fetch_assoc($res)) {
  		$markerArray = array();
  		$template["detail"] = $this->cObj->getSubpart($this->templateCode,"###DETAIL_TEMPLATE###");

  		// imageConfig of thumbs
      $img = explode(',',$row["image"]);
  		$imgTSConfig = Array();
  		$imgTSConfig['file'] = 'uploads/tx_rgthumbs/'.$img[0];
  		$imgTSConfig['altText'] = $row["title"];
  		$imgTSConfig['titleText'] = $row["title"];
  		$imgTSConfig['file.']['maxW'] = $this->conf['listMaxW'];
  		$imgTSConfig['file.']['maxH'] = $this->conf['listMaxH'];
  		$markerArray['###IMAGE###'] = $this->cObj->IMAGE($imgTSConfig);
  		$wrappedSubpartArray['###LINK###'] = explode('|', $this->pi_linkTP_keepPIvars('|', Array('uid'=>$row["uid"]), 1,1,$this->conf['detail']));
  		
  		// current thumbnail
      if ($uid == $row['uid']) $markerArray['###ACT###'] = 'rgthumbs-act';
      else $markerArray['###ACT###'] = 'rgthumbs';
  		  
			$content_item .= $this->cObj->substituteMarkerArrayCached($template["item"],$markerArray, $subpartArray,$wrappedSubpartArray );			
		} # end while
		$subpartArray["###CONTENT###"] = $content_item;

		$content .= $this->cObj->substituteMarkerArrayCached($template["total"],$markerArray, $subpartArray,$wrappedSubpartArray);
		return $content;

Template:

		<!-- ###LIST_TEMPLATE### -->
Liste
<div class="rgthumbs-list">
<ul>
<!-- ###CONTENT### --><!-- ###ITEM_SINGLE### -->
  <li class="###ACT###"><!-- ###LINK### -->###IMAGE###<!-- ###LINK### --></li>
<!-- ###ITEM_SINGLE### --><!-- ###CONTENT### -->
</ul>
</div>
<!-- ###LIST_TEMPLATE### -->

viel erfolg
georg

tobias_sa84 ·

Tut mir leid aber dieses Beispiel hilft mir gar nicht weiter, vor allem ohne erklärung.

Also nochmal zur erläuterung

Habe Preiskategorien und dazugehörige Preise aus verschiedenen Tabellen die ich über 2 Schleifen auslese, die erste SChleife holt die Kategorie und die zweite die dazu gehörigen Preis.

Sollte dann so aussehen

Preise Getränke:
Kalte Getränke - 0,80€
Warme Getränke - 0,80€
Preise belegte Brote:
Sandwitch - 1,20€
Brötchen - 1,40€

Das Problem ist momentan wird es so ausgeben:

Preise Getränke:
Kalte Getränke - 0,80€
Preise Getränke:
Warme Getränke - 0,80€
Preise belegte Brote:
Sandwitch - 1,20€
Preise belegte Brote:
Brötchen - 1,40€

Wäre schön wenn wer weiter wüßte!

Vielen Dank für eure Geduld.

Gruß

Tobias
[/list]