[TYPO3-german] Extension Entwicklung Template Einbinden

Basti Baumann donillo at gmail.com
Mon Apr 23 10:23:35 CEST 2007


Fabian Koenig schrieb:
> Immerwieder gern. :-)
> 
> 
> Tobias Sasse schrieb:
>> Super so funktioniert es :), bin dir sehr Dankbar.
>>
>> Schönen Tag noch und freundlichen Gruß
>> Tobias
>>
>> Fabian Koenig schrieb:
>>> Hi!
>>>
>>> Als erstes versuch es am besten mal mit dem Template:
>>>
>>> ==HTML:Template==
>>> <!-- ###TEMPLATE### begin -->
>>>    <table>
>>>      <!-- ###CONTENT### begin-->
>>>        <!-- ###LIST_ITEM### begin -->
>>>          <tr>
>>>            <td>###VALUE_NR###</td>
>>>            <td>###VALUE_NAME###</td>
>>>            <td>###VALUE_DESCRIPTION###</td>
>>>            <td>###VALUE_ACTION###</td>
>>>          </tr>
>>>        <!-- ###LIST_ITEM### end -->
>>>      <!-- ###CONTENT### end-->
>>>    </table>
>>> <!-- ###TEMPLATE### end -->
>>> ==HTML:Template==
>>>
>>> Und mit folgendem script:
>>>
>>> ==PHP==
>>> $this->templateCode = 
>>> $this->cObj->fileResource($this->conf['templateFile']);
>>>
>>> $template['template'] = 
>>> $this->cObj->getSubpart($this->templateCode,'###TEMPLATE###');
>>> $template['listItem'] = 
>>> $this->cObj->getSubpart($template['template'],'###LIST_ITEM###');
>>>
>>>
>>> // Hier kommt deine Datenbankabfrage rein.
>>> // Beispiel: $res = 
>>> $GLOBALS['TYPO3_DB']->exec_SELECTquery($fieldList,$table,$whereClause,$groupBy,$orderBy,$limit); 
>>>
>>> $res = ...
>>>
>>>
>>> while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
>>>   $markerArray['###VALUE_NR###'] = $row['nr'];
>>>   $markerArray['###VALUE_NAME###'] = $row['name'];
>>>   $markerArray['###VALUE_DESCRIPTION###'] = $row['description'];
>>>   $markerArray['###VALUE_ACTION###'] = $row['action'];
>>>   $content_item .= 
>>> $this->cObj->substituteMarkerArrayCached($template['listItem'], 
>>> $markerArray);
>>> }
>>>
>>> $subpartArray['###CONTENT###'] = $content_item;
>>>
>>> $content = 
>>> $this->cObj->substituteMarkerArrayCached($template['template'], 
>>> array(), $subpartArray);
>>> return $content;
>>> ==PHP==
>>>
>>>
>>>
>>> Hoffe es hilft.
>>> Wenn nicht -> Weiter fragen ^^
>>> $GLOBALS['TYPO3_DB']->MfG('Fabian König');
>>>
>>>
>>>
>>>
>>> Tobias Sasse schrieb:
>>>  
>>>> Hallo zusammen,
>>>>
>>>> habe gerade mittel großes verständis Problem:
>>>>
>>>> Möchte eine Extension entwickeln und stecke nun beim Einbinden des 
>>>> HTML Templates:
>>>>
>>>> Also es geht um die Ausgabe einer Liste die in etwa so aussehen sollte:
>>>>
>>>> Name  |  Beschreibung   |  Aktion
>>>> ----------------------------------
>>>> Hans   |   Neter Kerl      | Anschauen
>>>> Peter   |   Guter Läufer   | Anschauen
>>>>
>>>>
>>>> usw.
>>>>
>>>> mein Template sieht wie folgt aus:
>>>>
>>>> <!-- ###CONTENT### begin-->
>>>>    <table>
>>>>        <tr>
>>>>            <td>###LABEL_NR###</td>
>>>>            <td>###LABEL_NAME###</td>
>>>>            <td>###LABEL_DESCRIPTION###</td>
>>>>            <td>###LABEL_ACTION###</td>
>>>>        </tr>
>>>>    <!-- ###LIST_ITEM### begin -->
>>>>            <tr>
>>>>                <td>###VALUE_NR###</td>
>>>>                <td>###VALUE_NAME###</td>
>>>>                <td>###VALUE_DESCRIPTION###</td>
>>>>                <td>###VALUE_ACTION###</td>
>>>>            </tr>
>>>>              <!-- ###LIST_ITEM### end -->
>>>>    </table>
>>>> <!-- ###CONTENT### end-->
>>>>
>>>> Jetzt bekomme ich es nicht hin das die Marker richtig ersetzt 
>>>> werden, kann mir da wohl wer helfen?!?
>>>>
>>>> http://wiki.typo3.org/index.php/Extension_Development,_using_HTML-Templates 
>>>>
>>>>
>>>> Habe mit hilfe dieser Anleitung nen Ansatz ausprobiert und 
>>>> verstricke mich irgendwie immer wieder :(.
>>>>
>>>> Mit freundlichen Grüßen
>>>> Tobias
>>>>
>>>>     
>>>
>>>
>>> _______________________________________________
>>> TYPO3-german mailing list
>>> TYPO3-german at lists.netfielders.de
>>> http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-german
>>>
>>>   
>>

Hi,

ich häng mich da mal hin ;)
Ich habe fast das gleiche Problem wie Tobias.
Habe per Kickstarter eine Extension angelegt und will mir das nun auch 
per Template ausgeben lassen.
Nun habe ich zum einen das Problem, dass ich nicht wirklich weis, ich 
ich der Extension beibringe, dass es meinen Templatepfad aus der 
ext_typoscript_setup.txt ausliest.
Das habe ich aber immerhin umgangen, indem ich das Template so abfrage:
===PHP===
if(isset($this->conf['templateFile']) && $this->conf['templateFile'] != ""){
			$this->templateCode = 
$this->cObj->fileResource($this->conf['templateFile']);
		}else{
			$this->templateCode = 
$this->cObj->fileResource("EXT:sb_partner/sb_partner_template.html");
		}
===PHP===

Wie bringe ich das denn noch meiner Extension bei?

Nun zu meinem größeren Problem.
Ich habe mich an die Anleitung von Fabian gehalten und so meine function 
main bestückt:

===PHP===
	function main($content,$conf)	{
		$this->conf=$conf;
		$this->pi_setPiVarDefaults();
		$this->pi_loadLL();
		if(isset($this->conf['templateFile']) && $this->conf['templateFile'] 
!= ""){
			$this->templateCode = 
$this->cObj->fileResource($this->conf['templateFile']);
		}else{
			$this->templateCode = 
$this->cObj->fileResource("EXT:sb_partner/sb_partner_template.html");
		}
		$content=$this->templateCode;

     $this->templateCode = $this->cObj->fileResource($this->templateCode);

     $template['template'] = 
$this->cObj->getSubpart($this->templateCode,'###TEMPLATE###');
     $template['listItem'] = 
$this->cObj->getSubpart($template['template'],'###LIST_ITEM###');


     // Hier kommt deine Datenbankabfrage rein.
     // Beispiel: $res = 
$GLOBALS['TYPO3_DB']->exec_SELECTquery($fieldList,$table,$whereClause,$groupBy,$orderBy,$limit);

     $res = 
$GLOBALS['TYPO3_DB']->exec_SELECTquery('*','tx_sbpartner_partner','tx_sbpartner_partner.hidden=0');


     while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
      $markerArray['###COMPANY###'] = $row['company'];
      $markerArray['###FIRSTNAME###'] = $row['firstname'];
      $markerArray['###LASTNAME###'] = $row['lastname'];
      $markerArray['###ADDRESS###'] = $row['address'];
      $markerArray['###ZIP###'] = $row['zip'];
      $markerArray['###CITY###'] = $row['city'];
      $markerArray['###COUNTRY###'] = $row['country'];
      $content_item .= 
$this->cObj->substituteMarkerArrayCached($template['listItem'], 
$markerArray);
     }

     $subpartArray['###CONTENT###'] = $content_item;

     $content = 
$this->cObj->substituteMarkerArrayCached($template['template'], array(), 
$subpartArray);
	  return $content;
	}
}
===PHP===

Allerdings wird dabei rein gar nichts ausgegeben.
So sieht mein Template aus:
===HTML===
<!-- ###TEMPLATE### begin -->
      <table>
   <!-- ###CONTENT### begin-->
      <!-- ###LIST_ITEM### begin -->
              <tr>
                  <td>###COMPANY###</td>
                  <td>###FIRSTNAME### ###LASTNAME###</td>
                  <td>###ADDRESS</td>
                  <td>###ZIP### ###CITY###</td>
                  <td>###COUNTRY###</td>
              </tr>
       <!-- ###LIST_ITEM### end -->
   <!-- ###CONTENT### end-->
       </table>
<!-- ###TEMPLATE### end -->
===HTML===

Wenn ich dagegen in der Funktion eine normale SQL Abfrage mache:

$abfrage = "SELECT * FROM tx_sbpartner_partner";
   $ergebnis = mysql_query($abfrage);
   	$res = '';
	  while($row = mysql_fetch_object($ergebnis))
	    {
	    $res.=$row->company;
	    }
		$content = $res;
Dann bekomme ich zumindest meine Werte ausgegeben.

Nun ist die Frage, was mache ich falsch....

Danke schon einmal.

Grüße
Basti


More information about the TYPO3-german mailing list