Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fail-fast: false
matrix:
php: [8.1]
statamic: [4.0.*, 5.0.*]
statamic: [4.6.*, 5.*]
os: [ubuntu-latest]
laravel: [10.*]
testbench: [8.*]
Expand Down
6 changes: 6 additions & 0 deletions src/Tags/Toc.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ class Toc extends Tags
*/
public function index()
{
if ($this->params->get('when', true) === false) {
return [];
}

// get the supported header-levels

// get the supported header-levels
$depth = $this->params->int("depth", 3);
$start = $this->params->get('from', "h1");
Expand Down
50 changes: 50 additions & 0 deletions tests/Unit/RecursionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Tests\Unit;

use Goldnead\StatamicToc\Tests\TestCase;
use Statamic\Facades\Antlers;

class RecursionTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
app('statamic.tags')->put('toc', \Goldnead\StatamicToc\Tags\Toc::class);
}

/** @test */
public function it_renders_toc_with_when_param()
{
$content = '<h1>Heading 1</h1><h2>Heading 2</h2>';

$template = <<<'EOT'
<ol>
{{ toc field="content" :when="show_toc" }}
<li>
<a href="#{{ toc_id }}">{{ toc_title }}</a>
{{ if children }}
<ol>
{{ *recursive children* }}
</ol>
{{ /if }}
</li>
{{ /toc }}
</ol>
EOT;

$data = [
'content' => $content,
'show_toc' => true,
];

$output = (string) Antlers::parse($template, $data);

$this->assertStringContainsString('Heading 1', $output);

// Test false
$data['show_toc'] = false;
$output = (string) Antlers::parse($template, $data);
$this->assertStringNotContainsString('Heading 1', $output);
}
}
Loading