Picture of a opened gift box

Unwrapped

Categories:

Update April 2019

This post is a bit out of date and valid for Neos 1.0 to 2.3.

For Neos 3+ you can override the class of the ContentCollection like this:

foo = Neos.Neos:ContentCollection {
attributes.class = "my-wrapper-class"
}

This should already solve most use cases as one usually has a wrapper div around a group of items.

Of course you can still override the implementation class and you just need to adapt the code examples below to the new name spaces etc...

Why the what?

By default the Neos CMS 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.