Skip to content

Commit

Permalink
Remove delimiter for Breadcrumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
Simbiat committed Jul 10, 2021
1 parent e168d6d commit 94c4ba1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
3 changes: 1 addition & 2 deletions doc/HTML.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ Functions, that generate useful HTML code.

## breadcrumbs
```php
breadcrumbs(array $items, string $delimiter = '>', bool $links = false, bool $headers = false);
breadcrumbs(array $items, bool $links = false, bool $headers = false);
```
Generates breadcrumbs for your website in Microdata format (as per https://schema.org/BreadcrumbList) wrapping it in proper `<nav>` tag with `id` attributes for `<li>`, `<a>`, `<span>` tags, as well as useful `aria` attributes, where applicable. `id` values are structures in a way, that allows you to style items depending on their "level" (for example always hide first element, since it's supposed to be your home page): first item will always have an `id` ending with `0` and the last one - with `1`.
`$items` is an array of the items (arrays) you plan to present as breadcrumbs. Each array needs to have `href` and `name` elements, otherwise it will be skipped.
`$delimiter` is an optional delimiter, that you want to use between elements in breadcrumb. Usually this is a `>` symbol, which is set by default, but you can replace it with whatever you want (for example `<i class="bread-delimiter"></i>` to have some unique icon).
`$links` - if set to `false`, you will get just a string of the requested breadcrumbs, but if set to `true`, this will also generate values for `rel="home index top begin prefetch"` and `rel="up prefetch"` required for `Links()` [function](Headers.md#links), and thus function will return an array like this:
```php
[
Expand Down
6 changes: 2 additions & 4 deletions src/HTTP20/HTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class HTML
public static int $paginations = 0;

#Function to generate breadcrumbs for your website in Microdata format as per https://schema.org/BreadcrumbList
public function breadcrumbs(array $items, string $delimiter = '>', bool $links = false, bool $headers = false): string|array
public function breadcrumbs(array $items, bool $links = false, bool $headers = false): string|array
{
#Sanitize $items
foreach ($items as $key=>$item) {
Expand All @@ -33,8 +33,6 @@ public function breadcrumbs(array $items, string $delimiter = '>', bool $links =
}
#Increase the count for crumbs
self::$crumbs++;
#Sanitise delimiter and wrap it in a span
$delimiter = '<span class="delimiter_breadcrumbs_'.self::$crumbs.'">'.htmlspecialchars($delimiter).'</span>';
#Set initial item number (position)
$position = 1;
#Set depth of the item. This is, essentially, position in reverse. Useful in case you want to hide some of the elements in the list. Adding 1 to avoid last element getting ID of 0.
Expand All @@ -59,7 +57,7 @@ public function breadcrumbs(array $items, string $delimiter = '>', bool $links =
}
}
#Implode items and add them to output
$output .= implode($delimiter, $items);
$output .= implode('', $items);
#Close data
$output .= '</ol></nav>';
if ($links) {
Expand Down

0 comments on commit 94c4ba1

Please sign in to comment.