9. 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',
        ]);
    }
}
1
2
3
4
5
{% extends '@SonataClassification/Block/base_block_categories.html.twig' %}

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