From f85fde80b9e68636bfe78cf19a460073afbbbbe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Schwei=C3=9Finger?= Date: Thu, 20 Apr 2023 17:33:38 +0200 Subject: [PATCH] feat: add count tag --- README.md | 10 +++++++++- src/Tags/AnchorNavigation.php | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 64f3a53..f8ee1b6 100644 --- a/README.md +++ b/README.md @@ -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 @@ -28,6 +28,14 @@ Include the `{{ anchor_navigation }}` tag in your template and supply the field ``` +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. diff --git a/src/Tags/AnchorNavigation.php b/src/Tags/AnchorNavigation.php index dae93f7..bc791dc 100644 --- a/src/Tags/AnchorNavigation.php +++ b/src/Tags/AnchorNavigation.php @@ -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 {