-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into effectiveVolto2023
- Loading branch information
Showing
18 changed files
with
2,487 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
--- | ||
myst: | ||
html_meta: | ||
"description": "How to extend volto blocks" | ||
"property=og:description": "How to extend volto blocks" | ||
"property=og:title": "Extend volto blocks" | ||
"keywords": "Volto, Training, Extend block" | ||
--- | ||
|
||
# Extend volto blocks | ||
|
||
There are various ways of extending Volto blocks. | ||
Component shadowing (see last chapter) is a very basic to customize components in volto. | ||
But it comes with its own problems like keeping the shadowed component up to date with latest fixes and features of newer Volto versions. | ||
Instead of shadowing components we can: | ||
|
||
- Change the block-config | ||
- Extend blocks by adding new block-variations | ||
- Write add schemaEnhancer to modify blocks schema | ||
|
||
Let us first change the View of the teaser block which we already have in volto core by changing the block-configuration. | ||
In our addon `volto-teaser-tutorial` we will step by step extend each component that we have in volto core. | ||
|
||
The most simple customization is the View of the Teaser. The volto core teaser block configration (in `omelette/src/config/Blocks.jsx`) looks like: | ||
|
||
```{code-block} js | ||
teaser: { | ||
id: 'teaser', | ||
title: 'Teaser', | ||
icon: imagesSVG, | ||
group: 'common', | ||
view: TeaserViewBlock, | ||
edit: TeaserEditBlock, | ||
restricted: false, | ||
mostUsed: true, | ||
sidebarTab: 1, | ||
blockSchema: TeaserSchema, | ||
dataAdapter: TeaserBlockDataAdapter, | ||
variations: [ | ||
{ | ||
id: 'default', | ||
isDefault: true, | ||
title: 'Default', | ||
template: TeaserBlockDefaultBody, | ||
}, | ||
], | ||
}, | ||
``` | ||
|
||
Every block in Volto has Edit and View components. | ||
You can customize these individually by either shadowing or directly in the confuguration (`index.js` of your addon) like this: | ||
|
||
```{code-block} js | ||
import MyTeaserView from 'volto-teaser-tutorial/components/Blocks/Teaser/View' | ||
const applyConfig = (config) => { | ||
config.blocks.blocksConfig.teaser.view = MyTeaserView | ||
return config; | ||
} | ||
export default applyConfig; | ||
``` | ||
|
||
Of course we need to add our custom `MyTeaserView` component in our addon. | ||
From the root of the project that is `src/addon/volto-teaser-tutorial/src/components/Blocks/Teaser/View.jsx`: | ||
|
||
```{code-block} jsx | ||
import React from 'react'; | ||
import TeaserBody from '@plone/volto/components/manage/Blocks/Teaser/Body'; | ||
import { withBlockExtensions } from '@plone/volto/helpers'; | ||
const TeaserView = (props) => { | ||
return <TeaserBody {...props} extraProps={{ foo: 'bar' }} />; | ||
}; | ||
export default withBlockExtensions(TeaserView); | ||
``` | ||
|
||
Here, the View component renders a TeaserBody which will be a result of an active variation, we will come to that in later chapters. |
Oops, something went wrong.