stmllr.net

FE plugins need configurable baseWrap instead of static pi_wrapInBaseClass

by on stmllr.net

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.

Tags

Comments

  1. Mario Rimann

    Thanks for sharing this - helped me today :-)

  2. Steffen

    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.

  3. Søren Malling

    Could the check and stdWrap part be moved into the original pi_wrapInBaseClass function? In that way, you actually don't need the developers to change there code it becomes a part of the used function.

    And you avoid having this extra function inside your own code

  4. Steffen

    Hi Søren,

    in the beginning of this year I opened a bug for that and wrote a patch: http://bugs.typo3.org/view.php?id=10118

    Since then the patch was refactored many times (thanks to Lina, Ingo and Jigal). The patch is is still pending in the core list and needs +1.

Add a comment

Comments are moderated and need to approved. Please be patient.