# 39. Custom Block¶

In case you need some special look of a paragraph, a special behavior like an image gallery or even need to display data as chart, then you want to create your own block.

A very simple use case where the default text block can be extended to achieve the requested look and behavior is the following:

Use Case: The content of a page should be teasered: Show first part and the rest on click on "read more".

We extend the default Volto text block schema with an additional field "readmore".

src/customizations/components/manage/Blocks/Text/Schema.jsx

 1import BlockSettingsSchema from '@plone/volto/components/manage/Blocks/Block/Schema';
2
3const Schema = {
4    ...BlockSettingsSchema,
5    fieldsets: [
6        {
7            ...BlockSettingsSchema.fieldsets[0],
9        },
10    ],
11    properties: {
14        description: 'Hide following text. Show on Click.',
15        type: 'boolean',
16        },
17    },
18};
19
20export default Schema;


We use the Volto InlineForm component to extend the sidebar.

src/customizations/components/manage/Blocks/Text/Edit.jsx

 1import { SidebarPortal } from '@plone/volto/components';
2import InlineForm from '@plone/volto/components/manage/Form/InlineForm';
3
4import schema from './Schema';
5
6snip
7
8render() {
9
10snip
11
12    return (
13        <>
14            <SidebarPortal selected={this.props.selected}>
15                <InlineForm
16                    schema={schema}
17                    title={schema.title}
18                    onChangeField={(id, value) => {
19                        this.props.onChangeBlock(this.props.block, {
20                            ...this.props.data,
21                            [id]: value,
22                        });
23                    }}
24                    formData={this.props.data}
25                />
26            </SidebarPortal>


You see the call of onChangeBlock which writes the value true or false to the block data.

With the above customizations the default text block has an additional attribute "readmore".

The default text block has no options to select, so it is per default configured to show the document properties pane in sidebar and not the block pane. The following modification forces the sidebar to show the block configuration pane instead.

src/config.js

 1const customizedBlocks = {
2    text: {
3        ...config.blocks.blocksConfig.text,
4        sidebarTab: 1,
5    },
6};
7
8export const blocks = {
9    ...config.blocks,
10    blocksConfig: {
11        ...config.blocks.blocksConfig,
12        ...customBlocks,
13        ...customizedBlocks,
14    },
15};


The blocksConfig is modified by a setting for the text block: Show pane 1 (we have two panes: pane 0 with the document fields and pane 1 with the block fields which depend on the block type).

Now a view of the page can distinguish between content blocks to show and these to hide for further reading on click.

## 39.1. Exercise¶

Add a field highlighted to a default text block. With this marker you can add a CSS rule to highlight the blocks marked. Where would you place this CSS rule?

## 39.2. Prospect¶

That was easy. But what if we need a FAQ section and want to provide a nice form for question and answer pairs? See the next chapter where we create a new block type. We take the opportunity to create an add-on with this block type. So the feature can be easily applied to multiple projects.