Version

Documentation » Classification

« 6. Advanced usage

7. BlockBundle Integration

There is an (optional) integration with the SonataBlockBundle. This integration allows you to render dynamic lists on a page.

Here is a sample implementation for a custom category list block:

class CustomCategoriesBlockService extends AbstractCategoriesBlockService
{
    public function configureSettings(OptionsResolver $resolver)
    {
        parent::configureSettings($resolver);

        $resolver->setDefaults([
            'context' => 'custom',
            'template' => '@AcmeCustom/Block/block_categories.html.twig',
        ]);
    }

    public function getBlockMetadata($code = null)
    {
        return new Metadata($this->getName(), (!is_null($code) ? $code : $this->getName()), false, 'AcmeCustomBundle', [
            'class' => 'fa fa-folder-open-o',
        ]);
    }
}
{% extends '@SonataClassification/Block/base_block_categories.html.twig' %}

{% block link_category %}
    <a href="{{ path('acme_custom_category', { 'category': item.slug }) }}">{{ item.name }}</a>
{% endblock %}

Found a typo? Something is wrong in this documentation? Just fork and edit it!