You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/advanced-features/navigation-api.md
+112Lines changed: 112 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -157,6 +157,118 @@ The `NavigationMenu` class represents a navigation menu. It contains a collectio
157
157
158
158
The `NavigationItem` class represents a single item in a navigation menu. It contains information such as the destination link or route, a label, and priority for ordering in the menu.
159
159
160
+
Here is the constructor signature and a quick reference of the methods available on the `NavigationItem` class, and their types. Keep on reading to see more detailed examples and explanations.
161
+
162
+
```php
163
+
use Hyde\Framework\Features\Navigation\NavigationItem;
164
+
165
+
$item = new NavigationItem(Route|string $destination, string $label, int $priority = 500);
166
+
167
+
$item->getLink(): string; // Returns the resolved link route or destination URL.
168
+
$item->getLabel(): string; // Returns the label of the item.
169
+
$item->isActive(): bool; // Returns true if the item is the page being rendered.
170
+
$item->getPriority(): int; // Returns the priority of the item.
171
+
$item->getPage(): ?HydePage; // Returns the underlying Page instance, if there is one.
172
+
```
173
+
174
+
### Creating Navigation Items
175
+
176
+
There are several ways to create navigation items using the `NavigationItem` class.
177
+
178
+
#### Direct instantiation
179
+
180
+
You can create instances directly by passing either a URL or a Route instance to the constructor.
181
+
182
+
The first parameter is the destination, the second is the label, and the third optional parameter is the priority.
183
+
184
+
```php
185
+
$item = new NavigationItem('index', 'Home');
186
+
$item = new NavigationItem(Routes::get('index'), 'Home');
187
+
$item = new NavigationItem('https://example.com', 'External Link');
188
+
```
189
+
190
+
#### Setting Priority
191
+
192
+
You can set the priority of the item, which determines its position in the menu.
193
+
194
+
```php
195
+
$item = new NavigationItem(Routes::get('index'), 'Home', 25);
196
+
```
197
+
198
+
#### Static Creation Method
199
+
200
+
You can use the static `create` method, which can automatically fill in the label and priority from a Route.
0 commit comments