|
| 1 | +:navigation-title: Menus |
1 | 2 | .. include:: /Includes.rst.txt |
2 | | -.. _main-menu-creation: |
3 | 3 |
|
4 | | -========= |
5 | | -Main menu |
6 | | -========= |
| 4 | +.. _menu: |
7 | 5 |
|
8 | | -To display a main menu in our frontend output we need to provide the according |
9 | | -data and define the view by providing templates for it. |
| 6 | +======================== |
| 7 | +Rendering menus in TYPO3 |
| 8 | +======================== |
10 | 9 |
|
11 | | -A data processor (see :ref:`dataProcessing <t3tsref:dataProcessing>`) can be |
12 | | -used to provide the data for the menu to the template and a Fluid template |
13 | | -partial do define the view of the menu. |
| 10 | +There are several strategies to display menus or other navigation elements like |
| 11 | +breadcrumbs and sitemaps in TYPO3. |
14 | 12 |
|
15 | 13 | .. contents:: |
16 | 14 |
|
17 | | -.. _add-menu-processor: |
| 15 | +.. toctree:: |
| 16 | + :glob: |
| 17 | + :hidden: |
| 18 | + |
| 19 | + * |
| 20 | + |
| 21 | +.. _menu-content-element: |
| 22 | + |
| 23 | +Menus as content elements |
| 24 | +========================= |
| 25 | + |
| 26 | +You can use a content element to display a menu. In the example data "Page 1" |
| 27 | +contains a menu of subpages and page "Sitemap" a sitemap content element. |
| 28 | + |
| 29 | +To adjust the templates of these content elements refer to chapter |
| 30 | +`Overriding the default templates of content elements <https://docs.typo3.org/permalink/t3sitepackage:content-element-rendering>`_. |
| 31 | + |
| 32 | +.. _menu-page-view: |
| 33 | + |
| 34 | +Menus within the page view |
| 35 | +========================== |
18 | 36 |
|
19 | | -Use the data processor `menu` |
20 | | -============================= |
| 37 | +A data processor (see also :ref:`dataProcessing <t3tsref:dataProcessing>`) can be |
| 38 | +used to provide the data for one or several menus. |
21 | 39 |
|
22 | | -The :ref:`data processor 'menu' <t3tsref:MenuProcessor>` can be configured to |
23 | | -provide the data of all pages in your current site to your page template. |
| 40 | +For menus usually the `menu data processor <https://docs.typo3.org/permalink/t3tsref:menuprocessor>`_, |
| 41 | +which is provided by the TYPO3 Core, is used. |
24 | 42 |
|
25 | | -We save the TypoScript configuration for the menu into file |
26 | | -:file:`Configuration/Set/SitePackage/TypoScript/Navigation/menu.typoscript`: |
| 43 | +.. tip:: |
| 44 | + Some extensions like :composer:`b13/menus` offer performant menus for |
| 45 | + large sites or like :composer:`georgringer/news` menus for special purposes. |
| 46 | + |
| 47 | +.. _main-menu-creation: |
| 48 | +.. _add-menu-processor: |
| 49 | + |
| 50 | +TypoScrip configuration of the main menu |
| 51 | +======================================== |
| 52 | + |
| 53 | +We use TypoScript to configure these menus. The main menu is configured like this: |
27 | 54 |
|
28 | 55 | .. literalinclude:: /CodeSnippets/my_site_package/Configuration/Sets/SitePackage/TypoScript/Navigation/menu.typoscript |
29 | 56 | :caption: packages/my_site_package/Configuration/Sets/SitePackage/TypoScript/Navigation/menu.typoscript |
30 | 57 |
|
31 | | -.. _fluid-implement-main-menu: |
| 58 | +This menu defines that the variable with the default name `menu` should contain |
| 59 | +the information about the complete page tree of the current page. |
| 60 | + |
| 61 | +System folders like the "Footer menu" from your example data, special page types |
| 62 | +and pages excluded from the navigation are excluded. |
32 | 63 |
|
33 | | -Update the Fluid partial for the menu |
34 | | -===================================== |
| 64 | +A complete reference of this menu can be found in the TypoScript Reference: |
| 65 | +`menu data processor <https://docs.typo3.org/permalink/t3tsref:menuprocessor>`_. |
35 | 66 |
|
36 | | -Until now we had static HTML in the file |
37 | | -:file:`Resources/Private/PageView/Partials/Navigation/Menu.html`. |
| 67 | +.. _fluid-implement-main-menu: |
38 | 68 |
|
39 | | -We created that file in section :ref:`create_partial_header`. |
| 69 | +Fluid partial of the main menu |
| 70 | +============================== |
40 | 71 |
|
41 | | -Replace the static HTMl with Fluid: |
| 72 | +In :path:`packages/my_site_package/Resources/Private/PageView/Partials/Navigation/Menu.html` |
| 73 | +you can find the partial that renders the main menu. |
42 | 74 |
|
43 | 75 | A menu usually contains several menu entries. We use the |
44 | 76 | :ref:`t3viewhelper:typo3fluid-fluid-for` to iterate over all menu entries |
@@ -101,29 +133,27 @@ displayed in the :ref:`Fluid inline notation <t3coreapi:fluid-inline-notation>`. |
101 | 133 | Preview the page and use the menu |
102 | 134 | ================================= |
103 | 135 |
|
104 | | -The menu in the page should now function and allow you to navigate from page to |
105 | | -page. |
| 136 | +Whenever you change TypoScript files or Fluid templates, flush all caches: |
106 | 137 |
|
107 | | -Delete the frontend caches and preview the changes: |
| 138 | +.. code-block:: bash |
108 | 139 |
|
109 | | -When previewing the site as it stands now, we can verify if everything is |
110 | | -working as expected and if the menu is generated. Go to **WEB → View** and |
111 | | -check, if the menu reflects the pages you created in the backend. Add one or |
112 | | -two additional pages to the page tree and check to see if they appear in the preview. |
| 140 | + ddev typo3 cache:flush |
113 | 141 |
|
114 | 142 | .. figure:: /Images/MainMenuCreation/CheckMainMenu.png |
115 | 143 | :alt: Checking from the backend if the menu is generated as expected. |
116 | 144 | :class: with-shadow |
117 | 145 |
|
118 | 146 | Checking from the backend if the menu is generated as expected. |
119 | 147 |
|
120 | | -If the menu does not change, you possibly need to flush the frontend caches, |
121 | | -then reload the preview. |
| 148 | +.. _menu-types: |
122 | 149 |
|
123 | | -.. figure:: /Images/AutomaticScreenshots/FlushFrontendCaches.png |
124 | | - :class: with-shadow |
| 150 | +Different menu types |
| 151 | +==================== |
125 | 152 |
|
126 | | - Flush the frontend cache after changing template files |
| 153 | +We use the `menu data processor <https://docs.typo3.org/permalink/t3tsref:menuprocessor>`_ |
| 154 | +to demonstrate different menu types: |
127 | 155 |
|
128 | | -The preview in the screenshot above shows the menu with three page links: "Page |
129 | | -1", "Page 2" and "Page 3". |
| 156 | +* A breadcrumb configured in |
| 157 | + :file:`packages/my_site_package/Configuration/Sets/SitePackage/TypoScript/Navigation/breadcrumb.typoscript` |
| 158 | + and rendered in :file:`packages/my_site_package/Resources/Private/PageView/Partials/Navigation/Breadcrumb.html`. |
| 159 | +* A footer menu (example is still missing). |
0 commit comments