Nov. 26., 2008

FE plugins need configurable baseWrap instead of static pi_wrapInBaseClass

The output of most TYPO3 FE plugins are wrapped with a HTML div container by default (so called basewrap). This seems to be fair in most cases, but sometimes it is not and you have to get rid of them. Unfortunately, a lot of extensions including some of the most popular ones don't provide any control to handle this. This article describes how to do it better.

Problem

The convention to wrap the plugin content with an additional div container is not fair in any case. It should be configurable.

We usually find the following piece of code at the end of the main() function:

 return $this->pi_wrapInBaseClass($content);

The reason for this might be boilerplate code from the extension kickstarter.

Criticism

This is not only a lack in usability, but one more violation of the MVC pattern. The method adds additional HTML tags to the content. This should be part of the view and not the controller. One could make the objection that tslib_pibase anyway does not follow the MVC pattern. If so, we still have to face the usability aspect.

Solution

In TYPO3 the output can be controlled by TypoScript. We should make use of it to provide a baseWrap option making that stuff configurable:

public function main($content, $conf) {
// (...)
return $this->baseWrap($content);
}

protected function baseWrap($content) {
if (isset($this->conf['baseWrap.'])) {
return $this->cObj->stdWrap($content,$this->conf['baseWrap.']);
} else {
return $this->pi_wrapInBaseClass($content);
}
}

The content gets wrapped with the container by default, so backward compatibility is guaranteed. If user wishes to change that, he could use the stdWrap functions with baseWrap in his TS setup:

 plugin.tx_pluginname_pi1 {
# Remove basewrap div container
baseWrap.wrap = |
}

It takes you only a few minutes to do the magic.

Thanks to Francois Suter for his inspiration.

--> Back to the list of articles

Comments

  1. Mario Rimann wrote on May 20, 2009 at 15:51

    Thanks for sharing this - helped me today :-)

  2. Steffen wrote on May 20, 2009 at 17:51

    Mario, maybe you could support core bug #10118 which got stuck in the core list discussion. It's goal is to provide a backward compatible core solution for configurable baseWrap.


Leave a comment:

(will not be published)

CAPTCHA image for SPAM prevention Click here for audio version of the word to enter.

If you can't read the captcha word, please click to load a new image.
(You need Javascript turned on. Otherwise press the submit button and wait until the page has reloaded.)