Hab' ein kleines Tutorial auf Englisch erstellt, hoffe es hilft Dir weiter 🙂
In ext_typoscript_setup.txt write this:
plugin.tx_myextension_pi1.templateFile = EXT:my_extension_key/template.html
In the extension class this:
Simple Template
---------------
# Get the template
$this->templateCode = $this->cObj->fileResource($this->conf["templateFile"]);
# Get the parts out of the template
$template = array();
$template["total"] = $this->cObj->getSubpart($this->templateCode,"###MYTEMPLATE###");
# create the content by replacing the marker in the template
$markerArray = array();
$markerArray["###MARKER1###"] = $this->pi_getLL('MARKER1');
$markerArray["###MARKER1###"] = $this->pi_getLL('MARKER1');
...
$content = $this->cObj->substituteMarkerArrayCached($template["total"],$markerArray, array(), array());
return $content;
Simple Template looks like this:
--------------------------------
<h3>MYTEMPLATE</h3>
<!-- ###MYTEMPLATE### begin -->
<h1>###MARKER1###</h1>
<h1>###MARKER2###</h1>
<!-- ###MYTEMPLATE### end -->
Advanced Template
-----------------
Advanced template is basically the same like simple template but the markers between the <!-- ###CONTENT### --> will be replaced repeatly with the content from the database.
# Get the template
$this->templateCode = $this->cObj->fileResource($this->conf["templateFile"]);
# Get the parts out of the template
$template = array();
$template["total"] = $this->cObj->getSubpart($this->templateCode,"###MYTEMPLATE###");
$template["item"] = $this->cObj->getSubpart($template["total"],"###MYTEMPLATE_ITEM###");
# create the repeating content by replacing the marker in the template
$markerArray = array();
...
while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$markerArray["###MARKERITEM1###"] = $row['firstname'];
$markerArray["###MARKERITEM2###"] = $row['name'];
# Build content from template + array
$content_item .= $this->cObj->substituteMarkerArrayCached($template["item"], $markerArray, array(), array());
}
# Create the whole content
$subpartArray = array();
$subpartArray["###CONTENT###"] = $content_item;# Create the content by replacing the marker in the template
$markerArray = array();
$markerArray["###MARKER1###"] = $this->pi_getLL('MARKER1');
$markerArray["###MARKER1###"] = $this->pi_getLL('MARKER1');
$content = $this->cObj->substituteMarkerArrayCached($template["total"], $markerArray, $subpartArray, array());
return $content;
Advanced Template looks like this:
--------------------------------
<h3>MYTEMPLATE</h3>
<!-- ###MYTEMPLATE### begin -->
<h1>###MARKER1###</h1>
<h1>###MARKER2###</h1>
<table>
<!-- ###CONTENT### -->
<!-- ###MYTEMPLATE_ITEM### -->
<tr>
<td>###MARKERITEM1###</td><td>###MARKERITEM2###</td>
</tr>
<!-- ###MYTEMPLATE_ITEM### -->
<!-- ###CONTENT### -->
</table>
<!-- ###MYTEMPLATE### end -->