Skip to content

Commit aa931b0

Browse files
committed
fixup! Add slope_it_is_breadcrumb_empty Twig function (#13)
1 parent 28f83b4 commit aa931b0

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ Home > Value of entity property > Cool stuff
140140

141141
In which the first two items are anchors and the last one is text only.
142142

143+
Furthermore, in case you need to know whether the breadcrumb has items or not, you can use:
144+
145+
```
146+
{{ slope_it_is_breadcrumb_empty() }}
147+
```
148+
143149
### How the breadcrumb is generated
144150

145151
Under the hood, this is the business logic involved, for each item, in the breadcrumb generation:

src/Twig/BreadcrumbExtension.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function getFunctions(): array
4141
return [
4242
new TwigFunction(
4343
'slope_it_breadcrumb',
44-
[ $this, 'renderBreadcrumb' ],
44+
[$this, 'renderBreadcrumb'],
4545
[
4646
'is_safe' => [ 'html' ],
4747
'needs_environment' => true,
@@ -50,7 +50,7 @@ public function getFunctions(): array
5050
),
5151
new TwigFunction(
5252
'slope_it_is_breadcrumb_empty',
53-
[ $this, 'isBreadcrumbEmpty' ]
53+
[$this, 'isBreadcrumbEmpty']
5454
)
5555
];
5656
}
@@ -60,6 +60,11 @@ public function getName(): string
6060
return 'slope_it_breadcrumb';
6161
}
6262

63+
public function isBreadcrumbEmpty(): bool
64+
{
65+
return \count($this->builder->getItems()) === 0;
66+
}
67+
6368
public function renderBreadcrumb(Environment $twig, array $context): string
6469
{
6570
$breadcrumb = [];
@@ -69,9 +74,4 @@ public function renderBreadcrumb(Environment $twig, array $context): string
6974

7075
return $twig->render($this->template, [ 'items' => $breadcrumb ]);
7176
}
72-
73-
public function isBreadcrumbEmpty(): bool
74-
{
75-
return 0 === \count($this->builder->getItems());
76-
}
7777
}

0 commit comments

Comments
 (0)