Picture of a opened gift box

Unwrapped

Why the what?

By default the TYPO3 Neos content collection object has a wrap like <div class="neos-contentcollection"> when rendered.

Sometimes we don't want that because the resulting markup could be a problem for a third party javascript plugin for example.

We had exactly this problem in one of our projects and it couldn't be solved by using a different tag or setting a class on the wrap itself.

Our solution

Overwriting the default ContectCollectionImplementation class by providing our own modified one.

The class should look like in the following snippet.

You should put the class in your package into the path Classes/VendorName/SiteName/TypoScript

<?php
namespace VendorName\SiteName\TypoScript;

use TYPO3\TypoScript\TypoScriptObjects\AbstractCollectionImplementation;

class ContentCollectionImplementation extends \Neos\Neos\TypoScript\ContentCollectionImplementation {

	/**
	 * {@inheritdoc}
	 *
	 * @var string
	 */
	public function evaluate() {
		$contentCollectionNode = $this->getContentCollectionNode();
		if ($contentCollectionNode !== NULL && $contentCollectionNode->getContext()->getWorkspaceName() === 'live') {
			return AbstractCollectionImplementation::evaluate();
		}
		return parent::evaluate();
	}

}

By calling evaluate of the parent class AbstractCollectionImplementation only the content is rendered and not the wrap. But we only do this in the live workspace because we need the default wrap in the Neos backend so we have something clickable to edit.

Next you have to overwrite the prototype of the default TYPO3.Neos:ContentCollection TypoScript object.

# ----------------------------------------
# Override the Neos Content Collection
# To remove the default wrap in frontend
# ----------------------------------------
prototype(TYPO3.Neos:ContentCollection)[email protected] = 'VendorName\\SiteName\\TypoScript\\ContentCollectionImplementation'

Now all content collections should be without the default wrap when viewed in the front end.

Please send me an email or a tweet if you think there is a better solution or if you have any questions.

The solution is tested with Neos 1.0.x and Neos 1.1.0-beta2.