Skip to content

Commit b639c8a

Browse files
github-actions[bot]linawolffroemken
authored
[Backport 13.4] [FEATURE] Explain menu rendering with data processors (#1420)
* [FEATURE] Explain menu rendering with data processors Releases: main, 13.4, 12.4 * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Stefan Frömken <froemken@gmail.com> --------- Co-authored-by: lina.wolf <lwolf@w-commerce.de> Co-authored-by: Lina Wolf <48202465+linawolf@users.noreply.github.com> Co-authored-by: Stefan Frömken <froemken@gmail.com>
1 parent e544830 commit b639c8a

File tree

5 files changed

+55
-72
lines changed

5 files changed

+55
-72
lines changed

Documentation/Guide/Menu/Index.rst

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,38 @@
11
.. include:: /Includes.rst.txt
2-
32
.. _guide-menu:
43

5-
=============
6-
Create a menu
7-
=============
4+
=============================
5+
Create a menu with TypoScript
6+
=============================
87

98
Until now, we learned how the page *content* is rendered; however, the
109
page *navigation* is missing.
1110

12-
TYPO3 CMS offers a special menu object called
13-
:ref:`HMENU <cobj-hmenu>` ("H" stands for hierarchical) to easily build
14-
different kinds of menus.
15-
16-
We want our menu to be built like a nested list:
17-
18-
.. literalinclude:: _menu.html
19-
20-
It is customary to declare new objects as sub-properties of the
21-
`lib` top-level object. We can give it any name that hasn't
22-
been assigned yet:
23-
24-
.. literalinclude:: _lib.textmenu.typoscript
25-
26-
The :ref:`HMENU <cobj-hmenu>` object allows us to create a diversity of menus.
27-
The main properties are numbers and correspond to the menu level.
11+
TYPO3 provides a special data processor, the :ref:`menu data processor <MenuProcessor>`
12+
to pass data to render a menu to the Fluid template.
2813

29-
The :ref:`TMENU <tmenu>` object renders a menu level as
30-
text. A different
31-
rendering can be chosen for each menu level.
14+
Configure the data processor in TypoScript:
3215

33-
On every menu level, we can configure various states for the single
34-
menu items – see :ref:`menu items <menu-common-properties>`,
35-
e.g. `NO` for "normal", `ACT` for "pages in the root line"
36-
(i.e. the current page, its parent, grandparent, and so forth) or
37-
`CUR` for "the current page".
16+
.. literalinclude:: _menu.typoscript
17+
:caption: TypoScript Setup
3818

39-
.. important::
19+
And render the menu in your Fluid template. You need at least a
20+
:ref:`Minimal site package (see site package tutorial) <t3sitepackage:minimal-design>`
21+
to keep your templates in its private resources folder, for example
22+
:path:`/packages/site_package/Resources/Private/Templates`:
4023

41-
Except for the normal state (`NO`), other states have to be activated
42-
before they get displayed (i.e. `ACT = 1`).
24+
.. literalinclude:: _MenuTemplate.html
25+
:caption: /packages/site_package/Resources/Private/Templates/Pages/Default.html
4326

44-
Now that our menu is defined, we can use it with:
27+
Find more examples on how to configure and render menus with TypoScript and
28+
Fluid in chapter
29+
:ref:`Main menu of the Site Package Tutorial <t3sitepackage:main-menu-creation>`.
4530

46-
.. code-block:: typoscript
31+
You can find more examples on how to output menus of different styles, including
32+
multi-level menus, breadcrumbs, language menus, and sitemaps in the chapter
33+
about the :ref:`menu data processor <MenuProcessor>`.
4734

48-
page.5 < lib.textmenu
35+
.. note::
36+
Before data processors were introduced it was common to use the TypoScript
37+
object :ref:`HMENU <t3tsref:cobj-hmenu>` to render a menu. It is still
38+
possible doing so and you might see it in older examples.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<header>
2+
<ul class="navbar-nav">
3+
<f:for each="{myMainMenu}" as="menuItem">
4+
<li class="nav-item">
5+
<a class="nav-link {f:if(condition: menuItem.active, then:'active')}"
6+
href="{menuItem.link}"
7+
target="{menuItem.target}"
8+
title="{menuItem.title}"
9+
>
10+
{menuItem.title}
11+
</a>
12+
</li>
13+
</f:for>
14+
</ul>
15+
</header>
16+
<main>
17+
<p>Hello World!</p>
18+
</main>

Documentation/Guide/Menu/_lib.textmenu.typoscript

Lines changed: 0 additions & 29 deletions
This file was deleted.

Documentation/Guide/Menu/_menu.html

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
page = PAGE
2+
page {
3+
10 = FLUIDTEMPLATE
4+
10 {
5+
templateName = Default
6+
templateRootPaths.10 = EXT:site_package/Resources/Private/Templates/Pages/
7+
# ...
8+
dataProcessing {
9+
10 = menu
10+
10.as = myMainMenu
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)