Skip to content

Commit

Permalink
feat: add count tag
Browse files Browse the repository at this point in the history
  • Loading branch information
simonerd committed Apr 20, 2023
1 parent f51a1d4 commit f85fde8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A Statamic addon that provides a custom tag for creating an anchor nav for all h

## How to install

You can search for this addon in the `Tools > Addons` section of the Statamic control panel and click **install**, or run the following command from your project root:
Run the following command from your project root:

``` bash
composer require visuellverstehen/statamic-anchor-navigation
Expand All @@ -28,6 +28,14 @@ Include the `{{ anchor_navigation }}` tag in your template and supply the field
</ul>
```

You can get the amount of headings found within the content with the `count` tag:

```
{{ if {anchor_navigation:count from="bard"} > 0 }}
...
{{ /if }}
```

## Configurations

You can define which heading levels should be included in your anchor navigation. Level 2 headings are set as a default.
Expand Down
7 changes: 7 additions & 0 deletions src/Tags/AnchorNavigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public function index(): ?array

return self::collectHeadings();
}

public function count(): int
{
$headings = self::index() ?? [];

return count($headings);
}

private function defineAugmentor(): Augmentor
{
Expand Down

0 comments on commit f85fde8

Please sign in to comment.