|
7 | 7 | The jumbotron: Customize output of content elements |
8 | 8 | =================================================== |
9 | 9 |
|
10 | | -As you can see in the static html template, the jumbotron consist of a headline |
11 | | -and a text: |
| 10 | +.. contents:: |
12 | 11 |
|
13 | | -.. code-block:: html |
14 | | - :caption: theme/index.html |
| 12 | +.. _jumbotron-partial: |
15 | 13 |
|
16 | | - <div class="jumbotron"> |
17 | | - <div class="container"> |
18 | | - <h1 class="display-3">Hello, world!</h1> |
19 | | - <p> ... </p> |
20 | | - </div> |
21 | | - </div> |
| 14 | +The jumbotron partial template |
| 15 | +============================== |
22 | 16 |
|
23 | | -We could use a content element of type :guilabel:`Text` to store the needed |
24 | | -information. However the output of the default content element "Text" looks |
25 | | -like this: |
| 17 | +The partial of the jumbotron that we created in step |
| 18 | +:ref:`Split up the template into partials <t3sitepackage:partials>` still |
| 19 | +contains static content: |
26 | 20 |
|
27 | 21 | .. code-block:: html |
28 | | - :caption: Example HTML Output |
29 | | - |
30 | | - <div id="c215" class="frame frame-default frame-type-text frame-layout-0"> |
31 | | - <header> |
32 | | - <h2 class=""> |
33 | | - Hello World! |
34 | | - </h2> |
35 | | - </header> |
36 | | - <p>Lorem ipsum dolor sit amet, ...</p> |
| 22 | + :caption: packages/site_package/Resources/Private/Templates/Partials/Jumbotron.html |
| 23 | + |
| 24 | + <div class="container"> |
| 25 | + <div class="p-5 mb-4 bg-body-tertiary"> |
| 26 | + <div class="container-fluid py-5"> |
| 27 | + <h1 class="display-5 fw-bold">Custom jumbotron</h1> |
| 28 | + <p class="col-md-8 fs-4">This jumbotron contains a button to demonstrate that JavaScript is working: </p> |
| 29 | + <button class="btn btn-dark btn-lg" role="button" href="#" id="exampleButton">Example button</button> |
| 30 | + </div> |
37 | 31 | </div> |
38 | 32 |
|
39 | | -Also we do not want to output other types of content like images or forms. |
| 33 | +.. _jumbotron-content-records: |
40 | 34 |
|
41 | | -Open the partial displaying the jumbotron: |
42 | | -:file:`Resources/Private/Partials/Page/Jumbotron.html`. We already have the |
43 | | -data of content elements in the column "jumbotron" in a Fluid variable called |
44 | | -"jumbotronContent". |
| 35 | +Jumbotron content records |
| 36 | +========================= |
| 37 | + |
| 38 | +In our Fluid template the variable the variable `{content.jumbotron.records}` |
| 39 | +already contains the content of the content elements entered in columns |
| 40 | +`jumbotron` in the TYPO3 backend. This column was defined in the |
| 41 | +:ref:`Page layout <t3sitepackage:content-mapping-backend-layout>`. It is provided |
| 42 | +by the :ref:`page-content data processor <t3sitepackage:page-content-data-processor>`. |
45 | 43 |
|
46 | | -Now instead of letting extension :file:`fluid_styled_content` render the |
47 | | -content we will render it ourselves in this partial. Add the debug view helper |
48 | | -to the partial to see what the data of the jumbotronContent looks like: |
| 44 | +Open the partial displaying the jumbotron: |
| 45 | +:file:`Resources/Private/Partials/Page/Jumbotron.html`. Using the |
| 46 | +:ref:`Debug ViewHelper <f:debug> <t3viewhelper:typo3-fluid-debug>` have a look |
| 47 | +at what kind of data is passed to your partial template: |
49 | 48 |
|
50 | 49 | .. code-block:: html |
51 | 50 | :caption: EXT:site_package/Resources/Private/Partials/Page/Jumbotron.html |
52 | 51 |
|
| 52 | + <f:debug>{content.jumbotron.records}</f:debug> |
53 | 53 | <div class="jumbotron"> |
54 | | - <f:debug>{jumbotronContent}</f:debug> |
55 | 54 | <!-- ... --> |
56 | 55 | </div> |
57 | 56 |
|
58 | | -As you can see the data of the actually :sql:`tt_content` record can be found in |
59 | | -:typoscript:`data`. Now let us traverse the array and output the content |
60 | | -elements: |
| 57 | +.. _jumbotron-customized-rendering: |
61 | 58 |
|
62 | | -.. code-block:: html |
63 | | - :caption: EXT:site_package/Resources/Private/Partials/Page/Jumbotron.html |
| 59 | +Customized rendering of the content records |
| 60 | +=========================================== |
64 | 61 |
|
65 | | - <div class="jumbotron"> |
66 | | - <f:for each="{jumbotronContent}" as="contentElement"> |
67 | | - <div class="container"> |
68 | | - <h1 class="display-3">{contentElement.data.header}</h1> |
69 | | - <f:format.html>{contentElement.data.bodytext}</f:format.html> |
70 | | - </div> |
71 | | - </f:for> |
72 | | - </div> |
| 62 | +The variable will contain an array of :php:`\TYPO3\CMS\Core\Domain\Record` |
| 63 | +elements. If the array is empty. Check that your page indeed has content in |
| 64 | +the column "Jumbotron". |
| 65 | + |
| 66 | +You could render these content elements the way that we rendered the main content |
| 67 | +(compare :ref:`Extract the content element rendering to a |
| 68 | +partial <t3sitepackage:content-element-partial>`). However our expected HTML |
| 69 | +output is different from what fluid-styled-content produces out-of-the-box. |
| 70 | + |
| 71 | +Instead of letting the system extension fluid-styled-content render the |
| 72 | +content we will render it ourselves in this partial. |
| 73 | + |
| 74 | +We traverse the array provided by the page-content data processor and render |
| 75 | +the content ourselves: |
| 76 | + |
| 77 | +.. include:: /CodeSnippets/Fluid/PartialJumbotron.rst.txt |
| 78 | + |
| 79 | +The :ref:`For ViewHelper <f:for> <t3viewhelper:typo3fluid-fluid-for>` loops |
| 80 | +through all content elements in column jumbotron and provides them in variable |
| 81 | +`{record}`. |
| 82 | + |
| 83 | +The :php-short:`\TYPO3\CMS\Core\Domain\Record` object contains the information |
| 84 | +of the database row representing the current content element record. |
| 85 | +For advanced usage see :ref:`Use records in Fluid <t3coreapi:record_objects_fluid>`. |
| 86 | + |
| 87 | +Here we use the fields `header` and `bodytext` of the record. As the `bodytext` |
| 88 | +field has a rich-text editor in the backend, we pass it through the |
| 89 | +:ref:`Format.html ViewHelper <f:format.html> <t3viewhelper:typo3-fluid-format-html>`. |
0 commit comments