Nov. 26., 2008

FE plugins need configurable baseWrap instead of static pi_wrapInBaseClass

By Steffen Müller. Licensed under the Creative Commons License

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

License

Licensed under creative commonsThis article is licensed under the Creative Commons License CC BY-SA 3.0. You are free to share (copy, distribute and transmit) and to remix (to adapt) the work under the following conditions:

  • You must attribute the work by mentioning the name of the author (Steffen Müller) and setting a link back to the original article using its URL.
  • If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.

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.

  3. Søren Malling wrote on September 15, 2010 at 22:04

    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 wrote on September 16, 2010 at 09:01

    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.


Leave a comment:

This page uses static caches. Make sure you reload the page in your browser after posting 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.)