Add blueprints and a navigation bar snippet for generating a primary navigation bar of pages.
This commit is contained in:
24
blueprints/fields/link-location.yml
Normal file
24
blueprints/fields/link-location.yml
Normal file
@@ -0,0 +1,24 @@
|
||||
type: fields
|
||||
|
||||
fields:
|
||||
linkLocation:
|
||||
label: Link Location
|
||||
type: select
|
||||
options:
|
||||
type: query
|
||||
query: site.linkLocations.toStructure
|
||||
text: "{{ item.description }}"
|
||||
value: "{{ item.location }}"
|
||||
linkIndex:
|
||||
label: Link Position
|
||||
type: number
|
||||
min: 1
|
||||
default: 10
|
||||
linkText:
|
||||
label: Link Text
|
||||
help: Custom link text to use instead of the title.
|
||||
type: text
|
||||
linkIcon:
|
||||
label: Link Icon
|
||||
help: Font Awesome icon that is used for the link text.
|
||||
type: text
|
||||
15
blueprints/fields/link-locations.yml
Normal file
15
blueprints/fields/link-locations.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
type: fields
|
||||
|
||||
fields:
|
||||
linkLocations:
|
||||
label: Link Locations
|
||||
type: structure
|
||||
fields:
|
||||
description:
|
||||
label: Location Description
|
||||
type: text
|
||||
help: A friendly description for selecting this location on pages.
|
||||
location:
|
||||
label: Location Key
|
||||
type: text
|
||||
help: This is what is used when finding links for this location.
|
||||
@@ -21,6 +21,13 @@ Kirby::plugin(
|
||||
],
|
||||
],
|
||||
],
|
||||
"blueprints" => [
|
||||
"fields/link-locations" => __DIR__ . "/blueprints/fields/link-locations.yml",
|
||||
"fields/link-location" => __DIR__ . "/blueprints/fields/link-location.yml",
|
||||
],
|
||||
"snippets" => [
|
||||
"navbar/primary" => __DIR__ . "/snippets/navbar/primary.php",
|
||||
],
|
||||
"hooks" => [
|
||||
/**
|
||||
* To add this hook to a plugin, change the option() call to use the plugins name.
|
||||
|
||||
77
snippets/navbar/primary.php
Normal file
77
snippets/navbar/primary.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<ul class="navbar-nav me-auto">
|
||||
<?php foreach ($site->getLinkList("primary") as $link) : ?>
|
||||
<?php if (isset($link["dropdown"])) : ?>
|
||||
<?php ksort($link["dropdown"], SORT_NUMERIC) ?>
|
||||
<li class="nav-item dropdown">
|
||||
<a
|
||||
class="nav-link dropdown-toggle<?= (isset($link["active"]) and $link["active"]) ? " active" : "" ?><?= (isset($link["disabled"]) and $link["disabled"]) ? " disabled" : "" ?>"
|
||||
href="#"
|
||||
data-bs-toggle="dropdown"
|
||||
title="<?= $link["aria"] ?>"
|
||||
aria-label="<?= $link["aria"] ?>"
|
||||
>
|
||||
<?php if ($link["icon"]) : ?>
|
||||
<?= $link["icon"] ?>
|
||||
|
||||
<span class="d-md-none">
|
||||
<?php else : ?>
|
||||
<span>
|
||||
<?php endif ?>
|
||||
|
||||
<?= $link["text"] ?>
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<ul class="dropdown-menu">
|
||||
<?php foreach ($link["dropdown"] as $link) : ?>
|
||||
<li>
|
||||
<?php if (isset($link["divider"])) : ?>
|
||||
<hr class="dropdown-divider">
|
||||
<?php else : ?>
|
||||
<a
|
||||
class="dropdown-item<?= (isset($link["active"]) and $link["active"]) ? " active" : "" ?><?= (isset($link["disabled"]) and $link["disabled"]) ? " disabled" : "" ?>"
|
||||
href="<?= $link["url"] ?>"
|
||||
<?= isset($link["target"]) ? " target=\"{$link["target"]}\"" : "" ?>
|
||||
title="<?= $link["aria"] ?>"
|
||||
aria-label="<?= $link["aria"] ?>"
|
||||
>
|
||||
<?php if ($link["icon"]) : ?>
|
||||
<?= $link["icon"] ?>
|
||||
|
||||
<span class="d-md-none">
|
||||
<?php else : ?>
|
||||
<span>
|
||||
<?php endif ?>
|
||||
|
||||
<?= $link["text"] ?>
|
||||
</span>
|
||||
</a>
|
||||
<?php endif ?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</li>
|
||||
<?php else : ?>
|
||||
<li class="nav-item">
|
||||
<a
|
||||
class="nav-link<?= (isset($link["active"]) and $link["active"]) ? " active" : "" ?><?= (isset($link["disabled"]) and $link["disabled"]) ? " disabled" : "" ?>"
|
||||
href="<?= $link["url"] ?>"
|
||||
<?= isset($link["target"]) ? " target=\"{$link["target"]}\"" : "" ?>
|
||||
title="<?= $link["aria"] ?>"
|
||||
aria-label="<?= $link["aria"] ?>"
|
||||
>
|
||||
<?php if ($link["icon"]) : ?>
|
||||
<?= $link["icon"] ?>
|
||||
|
||||
<span class="d-md-none">
|
||||
<?php else : ?>
|
||||
<span>
|
||||
<?php endif ?>
|
||||
|
||||
<?= $link["text"] ?>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
Reference in New Issue
Block a user