Important

You are browsing the documentation for version 4.1 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Read version 5.1 (the latest LTS version) of the Oro documentation to get up-to-date 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 use Doctrine\Common\DataFixtures\AbstractFixture;
 2 use Doctrine\Common\Persistence\ObjectManager;
 3
 4 use Oro\Bundle\CMSBundle\Entity\ContentBlock;
 5 use Oro\Bundle\CMSBundle\Entity\TextContentVariant;
 6 use Oro\Bundle\LocaleBundle\Entity\LocalizedFallbackValue;
 7
 8 class LoadHomePageSlider extends AbstractFixture
 9 {
10     /**
11      * @param ObjectManager $manager
12      */
13     public function load(ObjectManager $manager)
14     {
15         $slider = new ContentBlock();
16         $slider->setAlias('marketing-block');
17
18         $title = new LocalizedFallbackValue();
19         $title->setString('Block title');
20         $slider->addTitle($title);
21
22         $variant = new TextContentVariant();
23         $variant->setDefault(true);
24         $variant->setContent('<p>Block content</p>');
25         $slider->addContentVariant($variant);
26
27         $manager->persist($slider);
28         $manager->flush($slider);
29     }
30 }

Render a Content Block in the Layout

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

1 layout:
2     actions:
3         - '@add':
4             id: marketing_block # unique layout block id
5             parentId: page_content
6             blockType: content_block
7             options:
8                 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.