Skip to content

Commit 44a8f7e

Browse files
committed
[FEATURE] Document Content Block Examples
Releases: main, 13.4
1 parent bad75bd commit 44a8f7e

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
:navigation-title: Custom Content Blocks
2+
.. include:: /Includes.rst.txt
3+
4+
.. _content-blocks:
5+
6+
=====================
7+
Custom Content Blocks
8+
=====================
9+
10+
When we filled the `stage with content <https://docs.typo3.org/permalink/t3sitepackage:slide-mode>`_
11+
we noticed that the content does not look like the content within the original
12+
HTMl layout.
13+
14+
This is because the stage does not contain normal content, as provided by
15+
Fluid-Styled Content, but a Jumbotron element or a slider.
16+
17+
.. note::
18+
The extension :composer:`friendsoftypo3/content-blocks` is not an official
19+
part of the TYPO3 Core yet. It is also possible to
20+
`Create a custom content element with TYPO3 Core only <https://docs.typo3.org/permalink/t3coreapi:adding-your-own-content-elements>`_.
21+
22+
.. _content-blocks-installation:
23+
24+
Install extension Content Blocks
25+
================================
26+
27+
The extension :composer:`friendsoftypo3/content-blocks` is an extension that
28+
is not part of the TYPO3 Core but maintained by a group of community members.
29+
30+
There are plans to integrate this extension into the Core, however at the
31+
time of writing there are no finite decisions yet.
32+
33+
First install the extension :composer:`friendsoftypo3/content-blocks`:
34+
35+
.. code-block:: bash
36+
37+
ddev composer req friendsoftypo3/content-blocks
38+
39+
Set up the extension and delete all caches:
40+
41+
.. code-block:: bash
42+
43+
ddev typo3 extension:setup
44+
ddev typo3 cache:flush
45+
46+
.. _content-blocks-jumbotron:
47+
48+
The jumbotron content block
49+
===========================
50+
51+
The site package you generated in step
52+
`Generate a site package <https://docs.typo3.org/permalink/t3sitepackage:minimal-design>`_
53+
comes with two content elements. We look at the more basic content elements first.
54+
55+
You can now replace the content element in the area "Stage" of start page with
56+
one of type "Jumbotron".
57+
58+
You can now create a jumbotron with a button and a link.
59+
60+
Directory :path:`packages/my_site_package/ContentBlocks/ContentElements` contains
61+
one directory for each Content Block that can be used as normal Content Elements.
62+
63+
.. _content-blocks-jumbotron-directory:
64+
65+
Directory structure of a content block
66+
--------------------------------------
67+
68+
A content block consists of a configuration (:file:`config.yaml`), a template and
69+
optionally assets and or language files:
70+
71+
The jumbotron consists of the following files:
72+
73+
.. directory-tree::
74+
:level: 2
75+
:show-file-icons: true
76+
77+
* packages/my_site_package/ContentBlocks/ContentElements/jumbotron
78+
79+
* assets
80+
81+
* icon.svg
82+
83+
* language
84+
85+
* labels.xlf
86+
87+
* templates
88+
89+
* frontend.html
90+
91+
* config.yaml
92+
93+
.. _content-blocks-jumbotron-config:
94+
95+
The configuration of the jumbotron Content Block
96+
------------------------------------------------
97+
98+
File :path:`packages/my_site_package/ContentBlocks/ContentElements/jumbotron/config.yaml`
99+
defines what fields should be available for the Content Block in the backend:
100+
101+
.. literalinclude:: /CodeSnippets/my_site_package/ContentBlocks/ContentElements/jumbotron/config.yaml
102+
:caption: packages/my_site_package/ContentBlocks/ContentElements/jumbotron/config.yaml
103+
:linenos:
104+
105+
Each content block must have a unique name with a prefix of your choice that
106+
should be unique within your project. (Line 1)
107+
108+
It is possible to use fields that are already pre-defined in the TYPO3 Core like
109+
`header` (Line 8) and `bodytext` (Line 11).
110+
111+
We also newly define two fields, one of type `Text <https://docs.typo3.org/permalink/friendsoftypo3/content-blocks:field-type-text>`_
112+
(Line 15-19) and one of type `Link <https://docs.typo3.org/permalink/friendsoftypo3/content-blocks:field-type-link>`_
113+
(Line 21-23). You can find all available types here: `Field Types <https://docs.typo3.org/permalink/friendsoftypo3/content-blocks:field-types>`_.
114+
115+
The meaning behind the other settings here can be found in the
116+
`YAML reference of the Content Blocks guide <https://docs.typo3.org/permalink/friendsoftypo3/content-blocks:yaml-reference>`_.
117+
118+
.. _content-blocks-jumbotron-template:
119+
120+
The jumbotron template
121+
----------------------
122+
123+
The frontend template for the Content Block "Jumbotron" is a normal Fluid
124+
template. You already used Fluid for the
125+
`Page templates <https://docs.typo3.org/permalink/t3sitepackage:fluid-templates>`_
126+
and to adjust the templates of Fluid-Styles Content elements in chapter
127+
`Overriding the default templates of content elements <https://docs.typo3.org/permalink/t3sitepackage:content-element-rendering>`_.
128+
129+
.. literalinclude:: /CodeSnippets/my_site_package/ContentBlocks/ContentElements/jumbotron/templates/frontend.html
130+
:caption: packages/my_site_package/ContentBlocks/ContentElements/jumbotron/templates/frontend.html
131+
:linenos:
132+
133+
Line 3: The values of the database entry of the current content element can be
134+
found in variable `{data}`. In this line we render the content of the field
135+
`header`. The field was defined in line 8 of the :file:`config.yaml`.
136+
137+
Line 4: Here we output the content of field `bodytext` as this field is a
138+
Rich-Text Editor we use the
139+
`Format.html ViewHelper <f:format.html> <https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-format-html>`_
140+
to format and sanitize the output.
141+
142+
Line 5: We use the `Link.typolink ViewHelper <f:link.typolink> <https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-link-typolink>`_
143+
to render a link to the target that was defined in our custom field `button_link`.
144+
145+
.. _content-blocks-next:
146+
147+
Next steps
148+
==========
149+
150+
* The generated site package contains a second, more elaborate example in
151+
directory :path:`packages/my_site_package/ContentBlocks/ContentElements/carousel`.
152+
* Learn how to use the `Kickstart command <https://docs.typo3.org/permalink/friendsoftypo3/content-blocks:cb-skeleton>`_
153+
to create your own content blocks.

0 commit comments

Comments
 (0)