Hallo,
beschäftige mich im rahmen meiner projektarbeit nun seit ca einem Monat mit Typo3, und seit ca 2-3 Wochen mit dem schreiben eigener extenions.
hab das grundgerüst mit dem kickstarter erstellt, und versuche im moment, ein template einzubinden, sodass die ausgaben einer DB-abfrage an die entsprechenden stellen gesetzt werden.
Die Extension soll eine Auflistung von Diplomarbeiten mit Autor, Titel, Betreuer, etc. ausgeben.
Leider steh ich da ziemlich auf dem Schlauch, hab schon google und die Suche in diesem Foruim bemüht, aber letztendlich doch nichts rausbekommen.
Mein template (provisorisch)
<BODY>
<H2>
Header of the page
</H2>
<TABLE WIDTH="600" BORDER="1" CELLSPACING="0" CELLPADDING="0">
<TR>
<TH>Art</TH>
<TH>Arbeit</TH>
<TH>Betreuer</TH>
<TH>Semester</TH>
<TH>Jahr</TH>
</TR>
<TR>
<TD ID="TYPE_OF_THESIS">Diplom</TD>
<TD ID="AUTHOR">Autor</TD>
<TD ID="TITLE">Titel</TD>
<TD ID="PROFESSOR">Professor</TD>
<TD ID="SEMESTER">Semester</TD>
</TR>
</TABLE>
</BODY>
</HTML>
TypoScript Setup code für die Seite, auf der die Ausgabe Extension dargestellt werden soll:
# Configuring the Auto-Parser for main template:
plugin.tx_automaketemplate_pi1 {
# Read the template file:
content = FILE
content.file = typo3conf/ext/theses_portal/pi1/template.html
# Here we define which elements in the HTML that
# should be wrapped in subpart-comments:
elements {
BODY.all = 1
BODY.all.subpartMarker = DOCUMENT_BODY
HEAD.all = 1
HEAD.all.subpartMarker = DOCUMENT_ACHEADER
HEAD.rmTagSections = title
TABLE.all = 1
TABLE.all.subpartMarker = TABLE
TR.all = 1
TR.all.subpartMarker = TABLE_ROW
TD.all = 1
}
# Prefix all relative paths with this value:
relPathPrefix = typo3conf/ext/theses_portal/pi1
}
# Main TEMPLATE cObject for the BODY
temp.mainTemplate = TEMPLATE
temp.mainTemplate {
# Feeding the content from the Auto-parser to the TEMPLATE cObject:
template =< plugin.tx_automaketemplate_pi1
# Select only the content between the <body>-tags
workOnSubpart = DOCUMENT_BODY
# Substitute the ###titel### subpart with some example content:
subparts.TITLE= TEXT
subparts.TITLE.value = HELLO WORLD - MENU
}
# Default PAGE object:
page = PAGE
page.typeNum = 0
# Copying the content from TEMPLATE for <body>-section:
page.10 < temp.mainTemplate
# Copying the content from TEMPLATE for <head>-section:
#page.headerData.10 < temp.headTemplate
und nun der "versuch" meiner extension
require_once(PATH_tslib."class.tslib_pibase.php");
class tx_thesesportal_pi1 extends tslib_pibase {
var $prefixId = "tx_thesesportal_pi1"; // Same as class name
var $scriptRelPath = "pi1/class.tx_thesesportal_pi1.php"; // Path to this script relative to the extension dir.
var $extKey = "theses_portal"; // The extension key.
/**
* [Put your description here]
*/
function main($content,$conf)
{
$this->conf=$conf;
$this->pi_setPiVarDefaults();
$this->pi_loadLL();
// Art der Arbeit, per GET übergeben
$type_of_thesis=t3lib_div::_GET('type_of_thesis');
$this->templateCode = $this->cObj->fileResource($this->conf["templateFile"]);
//SELECT-Abfrage, listet alle eingetragenen Arbeiten auf
$res=$GLOBALS['TYPO3_DB']->
exec_SELECTquery('tx_thesesportal_thesis.uid, tx_thesesportal_thesis.title,
tx_thesesportal_student.first_name sfirst, tx_thesesportal_student.last_name slast,
tx_thesesportal_professor.first_name pfirst, tx_thesesportal_professor.last_name plast,
tx_thesesportal_professor.title ptitle, tx_thesesportal_thesis.semester, tx_thesesportal_thesis.end_date,
tx_thesesportal_thesis.extern_company',
// END SELECT
'tx_thesesportal_thesis, tx_thesesportal_student, tx_thesesportal_professor',
// END FROM
'tx_thesesportal_thesis.fk_author=tx_thesesportal_student.uid
AND tx_thesesportal_thesis.fk_professor=tx_thesesportal_professor.uid
AND tx_thesesportal_thesis.type_of_thesis='.$type_of_thesis); /*.'
AND tx_thesesportal_thesis.extern_company IS NOT NULL';*/
// END WHERE
$row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
$markerArray['###TITLE###'] = $row["title"];
$markerArray['###AUTHOR###'] = $row["sfirst"].' '.$row["slast"];
$tablerow = $this->cObj->getSubpart($this->templateCode, '###TABLE_ROW###');
$content = $this->cObj->substituteMarkerArrayCached($tablerow, array(), $markerArray, array());
return $this->pi_wrapInBaseClass($content);
}
}
if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/theses_portal/pi1/class.tx_thesesportal_pi1.php"]) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/theses_portal/pi1/class.tx_thesesportal_pi1.php"]);
}
?>
Die Abfrage ist korrekt, die funktioniert so. Schleife fehlt, es ging mir erstmal um eine simple Ersetzung.
Allerdings komm ich mit dem ersetzen im Template nicht klar. Die Dokus erklären solche Dinge leider nicht so ausführlich, wie ich sie in meinem derzeitigen wissensstand benötige 🙁
Falls irgendetwas überflüssig ist (zB im Typo Script Setup Code) lasst es mich bitte auch wissen. Danke schonmal für jegliche Mühen!!