[TYPO3-mvc] Fluid templates options
Krystian Szymukowicz
k.szymukowicz at gmail.com
Tue Mar 5 17:21:05 CET 2013
W dniu 2013-03-05 15:49, janus wrote:
> Hi Everyone,
>
> Can an extbase extension use a different template file(s) than the
> one(s) defined in the extension typoscript. i.e be able to browse and
> select a file from within the plugin configuration form?
>
I do it like this.
1. In flexform of extension:
<settings.Default.default.templateFile>
<TCEforms>
<label>Template file (if empty the default will be choosen)</label>
<config>
<type>group</type>
<internal_type>file</internal_type>
<allowed>tpl,html</allowed>
<max_size>500</max_size>
<uploadfolder></uploadfolder>
<minitems>0</minitems>
<maxitems>1</maxitems>
<size>1</size>
</config>
</TCEforms>
</settings.Default.default.templateFile>
2. In controller or better some abstract controller
protected function initializeView(Tx_Extbase_MVC_View_ViewInterface $view) {
// overwrite default template
$controller = $this->request->getControllerName();
$action = $this->request->getControllerActionName();
if ($controller && $action) {
if ($this->settings['Default']['default']['templateFile']) {
// overwrite from flexform
$templateFile = $this->settings['Default']['default']['templateFile'];
} else {
// overwrite from typoscript
$templateFile = $this->settings[$controller][$action]['templateFile'];
}
if (file_exists(PATH_site . $templateFile) && $templateFile) {
$this->view->setTemplatePathAndFilename(PATH_site . $templateFile);
}
}
}
Take a look that you can also overwrite it from the TS if you user
special notation like:
settings {
ControllerA {
actionb {
templateFile = ....
}
}
ControllerZ {
actionx {
templateFile = ....
}
}
}
This all helps to keep settings chaos.
--
grtz
Krystian Szymukowicz
More information about the TYPO3-project-typo3v4mvc
mailing list