Archive for May, 2008
TemplaVoila in your own extension
Thursday, May 15th, 2008TemplaVoila is an incredibly smart tool for templating your TYPO3 website. However it cannot only be used for pages and fragments of pages (FCE:s), but also for templating your own extensions output.
The classic way of adding template support for an extension has been to use an HTML file marked with tags like
-
###MY_REPLACED_MARKER###
or similar that would be replaced by content using the cObj function substituteMarkerArrayCached:
-
$markerArray[‘###MY_REPLACED_MARKER###’] = $data;
-
$output = $this->cObj->substituteMarkerArrayCached($template, $markerArray);
Which is a quite simple and easy to use approach. The TemplaVoila way quite similiar. Let me show you a short example more or less cut from the mininews extension with a few simplifications for us mere mortals;
First off we will load up TV with a hard coded TO (Template Object) record uid. I suggest using some kind of FlexForm setting or similar for that
This part normally goes into an init() function or so;
-
// Load and initialize TemplaVoila TO (if any)
-
if (t3lib_extMgm::isLoaded(‘templavoila’)) {
-
$field_templateObject = 1; //read my default page "TO" record uid..
-
$this->TMPLobj = t3lib_div::makeInstance(‘tx_templavoila_htmlmarkup’);
-
$this->TMPLobj->setHeaderBodyParts($this->TMPLobj->tDat[‘MappingInfo_head’],$this->TMPLobj->tDat[‘MappingData_head_cached’]);
-
}
-
}
-
}
What the code above does is checking if TV exists, instantiates the templavoila HTML markup utility class (tx_templavoila_htmlmarkup), loads a TO record with uid one into it and finally sets some HTML header taggings..
Sooo, we got ourself a loaded TO with HTML template contents and also since TO always has a DS, we got the data structure fields (like field_mainMenu or similar). Next of is adding contents to where we’d like to have it. In our case into the field field_content mapped with TV.
-
//we got some content into $content var loaded from db earlier, now render it with TV
-
// Create list of elements:
-
$templatedResult = $this->TMPLobj->mergeDataArrayToTemplateArray(
-
$this->TA,
-
‘field_content’ => $content
-
)
-
);
-
}
-
$out = $templatedResult;
That’s it!
Using TemplaVoila for an extension has many benifits, just as using it for normal page rendering. One of them is the possibility to easily map your template using Templavoila. I suggest that you supply a valid datastructure (DS) xml with your extension, that gets loaded as static ds (again taken from mininews);
-
// Adding datastructure for Mininews:
-
‘title’ => ‘Mininews Template’,
-
‘path’ => ‘EXT:’.$_EXTKEY.‘/template_datastructure.xml’,
-
‘icon’ => ”,
-
‘scope’ => 0,
-
);
For a more detailed documentation around TV and the source to inspiration for this article, see the TemplaVoila extension documentation (http://typo3.org/documentation/document-library/extension-manuals/templavoila/1.3.4/view/1/6/)
jEdit with typoscript syntax highlighting
Tuesday, May 13th, 2008A short tip; If you’d like to have syntax highlight for your TypoScript code in jEdit on *.txt files (apart from *.ts), then you would first install the TypoScript plugin, and then set (for instance) “First line glob” field under Global options to
//TSFILE
and type the same on the first line in you ts file. The next time you open it, it will highlight your code. Simple and effective.
Upgraded wordpress
Tuesday, May 6th, 2008It was time to do another of those way to late updates. This time my WordPress installation (powering this blogg) was my target. Techie Buzz supplies a really neat update plugin that makes it safe and easy. Check it out
Although the auto update plugin was easy as a breeze to use, it wouldn’t hurt of having some more user friendly error handling when it gets write permission errors and such. They are handled but you get the feeling of being a bit stranded. I had some file writing permission problems..
I’m normally doing most of my work with or within the TYPO3 environment, and I must say that the clean and “just working” style of WP is a desirable target for the TYPO3 backend (and others) tool. Really neat.
Fixing an eclipse crach
Tuesday, May 6th, 2008Recently I wasn’t able to start up my Eclipse (vaugly remembering having an X-hangup – x-windows crach I mean). All I got was a small error dialog with a reference to eclipse log file containing huge traceback of java exceptions.. I didn’t have the time or energy to trace this so I swaped to jEdit for a while.
Sooner or later one has to deal with the problems. The later was today.. My method became deleting each plugin path under [workspace path]/.metadata/.plugins/
The solution was quite simple.. I removed the file .snap in the [workspace path]/.metadata/.plugins/org.eclipse.core.resources/ path and it started working again!
I’m no expert in how Eclipse handles it’s workspace data, but apparently I lost associated projects.. ..but that’s that not so tuff to add again.
