Zum Inhalt springen

extension -> setup -> template SUBPARTS,MARKER

Erstellt am 22. Juli 2005 · 8 Antworten · letzte Antwort am 28. Juli 2005

Tags: Templates & Layouts, Frage

serafim ·

hola typo3ler...

ich bin noch ganz am anfang und möchte mir meine eigene kleine extension programmieren.. meine ersten versuche habe ich auch schon hinter mir. eben diese extension schleudern mir aber nur statischen quelltext raus!!!

ich möchte natürlich typo3 sinngemäß programmieren und deshalb mit einem template programmieren... also alles was mir meine main funktion in der php datei erzeugt in (subpart)variablen packen -> im setup meine template datei einbinden -> und schön die subparts,marker befüllen!!!

kann mir irgend jemand eine kleine anleitung geben was ich da alles tun muss oder mich auf ein tutorial verweisen wo ich sowas finde!!

ich habe echt schon gesucht und finde gar nichts!!!

in der php datei hab ich an sowas gedacht wie eine schleife die mir
die mir ein subpart array erzeugt

template datei eben mit diesen subparts

und eben die setup die mir sowas ausgibt

ich wäre ja sowas von dankbar!!!!!

mfg falko

Stoneage ·

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 -->

just2b ·

Hallo Tetramatrix,

ah du warst das? :p
Hab das Tutorial mal in der deutschen Liste bekommen und hab so das begriffen.... danke von mir 😉

lg georg

serafim ·

aslo erstmal tausend dank für die antwort....

leider funzt das bei mir nicht....

ich habe mal mein completten quelltext(setup, class, und template) hgier reingestellt -> vielleicht kann da einer nochmal drüberschauen und sagen was fehlt

setup:

# setup
plugin.user_visitcounter_pi1.templateFile =
EXT:user_visitcounter/pi1/template_table.html

template:

<h3>MYTEMPLATE</h3>
<!-- ###MYTEMPLATE### begin -->
<h1>###MARKER1###</h1>
<h1>###MARKER2###</h1>
<!-- ###MYTEMPLATE### end -->

class datei:

require_once(PATH_t3lib."class.t3lib_xml.php");
require_once(PATH_tslib."class.tslib_pibase.php");

class user_visitcounter_pi1 extends tslib_pibase {
	var $prefixId = "user_visitcounter_pi1";		// Same as class name
	var $extKey = "user_visitcounter";	// The extension key.
	
	/**
	 * [Put your description here]
	 */
	function main($content,$conf)	{
		//$table_connect = mysql_connect("DB", "DBUSER", "DBPASS");
		//$row_arr = mysql_db_query("PETER", "SELECT * FROM BO_GAST LIMIT 0,20", $table_connect);
		
		
		
		
		# 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###"] = "hallo";
		$markerArray["###MARKER1###"] = "welt";
		
		$content = $this->cObj->substituteMarkerArrayCached($template["total"],$markerArray, array(), array());
		return $content;
	}
}



if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/user_visitcounter/pi1/class.user_visitcounter_pi1.php"])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/user_visitcounter/pi1/class.user_visitcounter_pi1.php"]);
}

wie mann sieht hab ich mich echt ans tutorial gehalten... was ist falsch????

mfg falko

serafim ·

ahaaaa - :o

ich habe den verdacht gehabt das mein template gar nicht eingebunden wird

die zeile:

$this->templateCode = $this->cObj->fileResource($this->conf["templateFile"]);

versucht ja meines erachtens die typoscript variable templateFile zu bekommen - dies ist aber leer!!! wenn ich den pfad direkt reinschreibe funzt das ganze!!!

WARUM GEHT DAT NICH????

just2b ·

ins blaue geraten: plugin.user_visitcounter den _ weg => plugin.uservisitcounter...

lg georg
ps: darum steht in den guidelines für ext. key: Avoid underscores if you can (stick to a-z0-9) - that will provide you with the least confusing naming of your modules, tables, classes...

serafim ·

also wenn du das so meinst:

plugin.user_visitcounter.templateFile = EXT:user_visitcounter/pi1/template_table.html

geht's auch nicht....

wie ist das mit dem setup -> muss irgendwo angegeben werden das die datei eingebunden werden soll???

serafim ·

😃 😃 😃 juhu es hat funktioniert!!!

vielen dank für alle hilfen....

wenn es $conf.... anstatt $this->conf.... heist - dann geht's!!! bedenklich??? o.O

Stoneage ·

wenn es $conf.... anstatt $this->conf.... heist - dann geht's!!! bedenklich???

Vielleicht, eigentlich reicht $conf aus. Ich muß mal mein Tutorial überarbeiten 😃