Step 3 — Use existing blocks¶
In this step you can add a Content List block and a Content Scheduler block and customize them.
Add a Content List block¶
First, create an override template for the Content List block: templates/blocks/contentlist/default.html.twig
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
Then add a configuration that tells the app to use this template instead of the default one.
In config/packages/ibexa_fieldtype_page.yaml
add the following code at the end of the file, under the ibexa_fieldtype_page
key on the same level as layouts
:
1 2 3 4 5 6 |
|
The template makes use of an image variation (line 10).
It's the thumbnail of the Dog Breed image that is displayed in the block.
To configure this variation, open the config/packages/image_variations.yaml
file and add the following code under the image_variations
key:
1 2 3 4 5 |
|
Finally, add some styling to the block. Add the following CSS to the end of the assets/css/style.css
file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
Run yarn encore <dev|prod>
to regenerate assets.
At this point you can start adding blocks to the page. You do it in the page's Edit mode by dragging a block from the menu on the right to the correct zone on the page.
Drag a Content List block from the menu to the left zone on the page. Click the block and fill in the form. Here you name the block and decide what it displays. Choose the "Dog Breed Catalog" folder as the Parent, select Dog Breed as the content type to be displayed, and choose a limit (3). Display the first three Dog Breeds from the database.
Click Submit and you should see a preview of what the block looks like with the dog breed information displayed.
The block is displayed using the new template. Built-in blocks have default templates included in a clean installation, but you can override them. Publish the page now and move on to creating another type of block.
Create a Content Scheduler block for featured articles¶
The next block is the Content Scheduler block that airs articles at predetermined times.
First, add a configuration that points to the layout.
Go to config/packages/ibexa_fieldtype_page.yaml
again and add the following code under blocks
on the same level as the contentlist
key:
1 2 3 4 5 |
|
The configuration defines one view for the Schedule block called featured
and points to a featured.html.twig
template.
Create the new file templates/blocks/schedule/featured.html.twig
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
When you look at the template, you can see three blocks, each of which render the content items using the featured
view (line 11).
So far you only have templates for full
view for Articles.
This means you need to create a featured
view template, otherwise you get an error when trying to add content to the block.
You need to modify the config/packages/views.yaml
file to indicate when to use the template.
Add the following code to this file, on the same level as the full
key:
1 2 3 4 5 |
|
Now create a templates/featured/article.html.twig
file:
1 2 3 4 |
|
Like in the case of the Content List block, the template specifies an image variation.
Add it in config/packages/image_variations.yaml
under the image_variations
key:
1 2 3 4 |
|
The Block is already operational, but first update the stylesheet.
Add the following CSS at the end of the assets/css/style.css
file:
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 |
|
Run yarn encore <dev|prod>
to regenerate assets.
At this point you can add a new Content Scheduler block to your page and fill it with content to see how it works.
Tip
If you don't see the featured block template, you may need to clear the cache (using php bin/console cache:clear
) and/or reload the app.
Go back to editing the Home page and drag a Content Scheduler block from the pane on the right to the main zone in the layout, above the Content List block. Select the block and click the Block Settings icon.
Set the Limit to three and click Select Content. Navigate to the "All Articles" folder and select the articles you had created and confirm.
Accept the suggested airtime and click Submit.
Now click the Airtime button next to one of the Articles and choose a time in the future. This article is listed in the queue.
Publish the page.
Now open the Timeline at the top of the screen. You can move the slider to different times and preview what the Content Scheduler block looks like at different hours. Content is shown when you move the slider to the point when it airs.
Tip
At this point you have configured the Content Scheduler block to work with Articles only.
If you try to add Content of any other type, you can see an error.
This is because there is no featured
view for content other than Articles defined at the moment.