[TYPO3-dev] My first (for me) advanced extension
S. Teuber
traveler_in_time at gmx.net
Fri Mar 17 13:29:29 CET 2006
Hi there,
> > - Where do I place the form? Above file or my html template file?
>
> For a start you can just implement it in the php-code but as you move
> forward you should take the time to look at how other plugins (e.g. the
> tt_news plugin) is using html-templates. Especially if you want to
> publish this extension in the TER.
Eeks. Please do yourself a favor and put the html to an external file
right from the start. As it's easier to maintain for you (no confusing
mx-up of HTML and PHP), and not more complex than the general concept of
putting things into markers (and markers into HTML), there's no real
downsides to this.
Accessing an external HTML file is pretty simple. I like to make the HTML
template a TypoScript contentObject to keep it highly configurable. Like
this:
HTML-Template, put in fileadmin/html/ and name my_ext_template.html:
--------------
<div><strong>###SOMEMARKER###</strong></div>
--------------
Typoscript-Template:
--------------
plugin.tx_myext_pi1 {
mytemplate = TEMPLATE // (or any other cObject, like HTML)
mytemplate.template = FILE
mytemplate.template.file = fileadmin/html/my_ext_template.html
}
// don't forget to put the plugin output in a marker, if it's not
// a plugin type "content element" which is fetched by styles.content.get
// for example:
// page.20.marks.MYEXTHERE < plugin.tx_myext_pi1
--------------
PHP-Code (in class.tx_myext_pi1.php):
--------------
function main($content, $conf)
{
// Making the TypoScript configuration globally
// available for all methods
$this->conf = $conf;
// Get the html template
$htmltemplate = $this->cObj->cObjGetSingle($this->conf
['mytemplate'], $this->conf['mytemplate.']);
// Set a demo marker
$markers = array('###SOMEMARKER### => 'Hello World');
// Parse markers into HTML and return the result
$content = $this->cObj->substituteMarkerArrayCached($htmltemplate,
$markers, array(), array());
return $content;
}
--------------
...simple as that. For explanations of the used cObj methods, take a look
at http://typo3.org/fileadmin/typo3api-3.8.0/df/d65/classtslib__cObj.html
For starters, it's sufficient to check out cObjGetSingle() and everything
that has a "substitute" as first word.
Sven
More information about the TYPO3-dev
mailing list