Skip to content

Commit 3f4f9b1

Browse files
committed
feat(navigation): Add navigation component and styles
- Implemented a new navigation component in Twig for rendering navigation items. - Added CSS styles for navigation layout and hover effects. - Updated CatchAllController to fetch navigation data and pass it to the template. - Refactored header template to include the navigation component within a grid layout.
1 parent 6b99446 commit 3f4f9b1

5 files changed

Lines changed: 85 additions & 7 deletions

File tree

examples/dotcms-symfony/assets/styles/app.css

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
body {
2-
background-color: skyblue;
3-
}
4-
51
/* Grid System */
62
.row {
73
display: grid;
@@ -35,3 +31,37 @@ body {
3531
.col-end-11 { grid-column-end: 11; }
3632
.col-end-12 { grid-column-end: 12; }
3733
.col-end-13 { grid-column-end: 13; }
34+
35+
/* Navigation styles */
36+
nav ul {
37+
display: flex;
38+
list-style: none;
39+
padding: 0;
40+
margin: 0;
41+
}
42+
43+
nav > ul > li {
44+
position: relative;
45+
margin-right: 1rem;
46+
}
47+
48+
nav ul ul {
49+
display: none;
50+
position: absolute;
51+
padding: 0.5rem;
52+
z-index: 100;
53+
flex-direction: column;
54+
min-width: 200px;
55+
}
56+
57+
nav ul li:hover > ul {
58+
display: flex;
59+
}
60+
61+
nav ul ul li {
62+
margin: 0.25rem 0;
63+
}
64+
65+
header .grid {
66+
align-items: center;
67+
}

examples/dotcms-symfony/src/Controller/CatchAllController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ public function show(string $path = ''): Response
3232
if (!$pageAsset || !isset($pageAsset->page)) {
3333
throw new NotFoundHttpException('Page not found');
3434
}
35+
36+
// Get navigation with depth of 2 (top level + one level of children)
37+
$navigation = $this->dotCMSService->getNavigation('/', 2);
3538

3639
return $this->render('page.html.twig', [
3740
'pageAsset' => $pageAsset,
3841
'layout' => $pageAsset->layout ?? null,
3942
'page' => $pageAsset->page ?? null,
40-
'containers' => $pageAsset->containers ?? []
43+
'containers' => $pageAsset->containers ?? [],
44+
'navigation' => $navigation
4145
]);
4246
} catch (HttpException $e) {
4347
// Map HTTP errors to appropriate Symfony exceptions

examples/dotcms-symfony/src/Service/DotCMSService.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Dotcms\PhpSdk\DotCMSClient;
66
use Dotcms\PhpSdk\Model\PageAsset;
7+
use Dotcms\PhpSdk\Model\NavigationItem;
78

89
class DotCMSService
910
{
@@ -27,4 +28,19 @@ public function getPage(string $path): PageAsset
2728

2829
return $this->client->getPage($pageRequest);
2930
}
31+
32+
/**
33+
* Get navigation items from DotCMS
34+
*
35+
* @param string $path The root path to begin traversing the folder tree
36+
* @param int $depth The depth of the folder tree to return
37+
* @param int $languageId The language ID of content to return
38+
* @return NavigationItem The navigation item with optional children
39+
*/
40+
public function getNavigation(string $path = '/', int $depth = 1, int $languageId = 1): NavigationItem
41+
{
42+
$navRequest = $this->client->createNavigationRequest($path, $depth, $languageId);
43+
44+
return $this->client->getNavigation($navRequest);
45+
}
3046
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{# Navigation component for DotCMS #}
2+
<nav class="container">
3+
<ul>
4+
{% if navigation is defined and navigation is not null %}
5+
{% for item in navigation.children %}
6+
<li>
7+
<a href="{{ item.href }}" target="{{ item.target }}">{{ item.title }}</a>
8+
{% if item.children is defined and item.children is not empty %}
9+
<ul>
10+
{% for child in item.children %}
11+
<li>
12+
<a href="{{ child.href }}" target="{{ child.target }}">{{ child.title }}</a>
13+
</li>
14+
{% endfor %}
15+
</ul>
16+
{% endif %}
17+
</li>
18+
{% endfor %}
19+
{% endif %}
20+
</ul>
21+
</nav>
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
<header class="container" style="background-color: rgba(0, 0, 0, 0.5); text-align: center;">
2-
<h1>{{ pageAsset.page.title }}</h1>
1+
<header class="container">
2+
<div class="grid">
3+
<div>
4+
<h1>{{ pageAsset.page.title }}</h1>
5+
</div>
6+
<div>
7+
{% include 'dotcms/components/navigation.twig' with { 'navigation': navigation } %}
8+
</div>
9+
</div>
310
</header>

0 commit comments

Comments
 (0)