Important

You are browsing the documentation for version 4.1 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Security Support ends in January 2023. Read version 5.0 (the latest LTS version) of the Oro documentation to get the updated information.

See our Release Process documentation for more information on the currently supported and upcoming releases.

Content Blocks

An administrator can modify a predefined marketing content in the frontend by editing the defined content blocks.

The ContentBlock entity fields consist of:

alias A unique identifier that can be used in the layout to render a block.
scopes A collection of scopes that defines the conditions for the content block to be displayed. For more information, refer to the ScopeBundle documentation.
titles A localized block title that can be rendered along with the scope.
contentVariants A collection of the TextContentVariant entities. Each content variant has a scope that defines when it should be rendered. Only one content variant with the most suitable scope is rendered at a time. If there is no suitable content variant, the default one is rendered instead.

Manage Content Blocks

An administrator can edit the defined content blocks in the Marketing > Content Blocks menu.

Create a Content Block

You can create content blocks with a collection of predefined content variants using data migrations:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 use Doctrine\Common\DataFixtures\AbstractFixture;
 use Doctrine\Common\Persistence\ObjectManager;

 use Oro\Bundle\CMSBundle\Entity\ContentBlock;
 use Oro\Bundle\CMSBundle\Entity\TextContentVariant;
 use Oro\Bundle\LocaleBundle\Entity\LocalizedFallbackValue;

 class LoadHomePageSlider extends AbstractFixture
 {
     /**
      * @param ObjectManager $manager
      */
     public function load(ObjectManager $manager)
     {
         $slider = new ContentBlock();
         $slider->setAlias('marketing-block');

         $title = new LocalizedFallbackValue();
         $title->setString('Block title');
         $slider->addTitle($title);

         $variant = new TextContentVariant();
         $variant->setDefault(true);
         $variant->setContent('<p>Block content</p>');
         $slider->addContentVariant($variant);

         $manager->persist($slider);
         $manager->flush($slider);
     }
 }

Render a Content Block in the Layout

Content blocks can be rendered by unique aliases using the content_block block type:

1
2
3
4
5
6
7
8
 layout:
     actions:
         - '@add':
             id: marketing_block # unique layout block id
             parentId: page_content
             blockType: content_block
             options:
                 alias: marketing-block # unique content block id

Note

An administrator can rename or delete defined content blocks. So if there is no content block with a defined alias, this may be caused by a typo in a block name or non-existence of the block itself, nothing is rendered, and no errors are displayed. A notice message is written to log.

If you have rendered a content block to the layout but nothing is displayed, check whether:

  • The content block is enabled
  • The content block has at least one suitable scope or has no scope at all, which means the block is rendered without any restriction.