Skip to content
Merged
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
7 changes: 6 additions & 1 deletion src/View/Antlers/Language/Runtime/RuntimeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ protected function isIgnitionInstalled()
return class_exists(ViewException::class) || class_exists('Spatie\LaravelIgnition\Exceptions\ViewException');
}

protected function shouldCacheRenderNodes($text)
{
return ! str_contains($text, '/noparse');
}

/**
* Parses and renders the input text, with the provided runtime data.
*
Expand Down Expand Up @@ -350,7 +355,7 @@ protected function renderText($text, $data = [])
$parseText = $this->sanitizePhp($text);
$cacheSlug = md5($parseText);

if (! array_key_exists($cacheSlug, self::$standardRenderNodeCache)) {
if (! array_key_exists($cacheSlug, self::$standardRenderNodeCache) || ! $this->shouldCacheRenderNodes($text)) {
$this->documentParser->setIsVirtual($this->view == '');

if (strlen($this->view) > 0) {
Expand Down
40 changes: 40 additions & 0 deletions tests/Antlers/Runtime/NoparseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

namespace Tests\Antlers\Runtime;

use Statamic\View\Antlers\Language\Runtime\GlobalRuntimeState;
use Statamic\View\Antlers\Language\Runtime\NodeProcessor;
use Statamic\View\Antlers\Language\Utilities\StringUtilities;
use Tests\Antlers\ParserTestCase;
use Tests\FakesViews;

class NoparseTest extends ParserTestCase
{
use FakesViews;

public function test_noparse_ignores_braces_entirely()
{
$template = <<<'EOT'
Expand Down Expand Up @@ -142,4 +147,39 @@ public function test_multiple_noparse_regions()

$this->assertSame($expected, StringUtilities::normalizeLineEndings(trim($this->renderString($template, ['title' => 'the title']))));
}

public function test_noparse_in_nested_partials_renders_correctly()
{
$template = <<<'EOT'
{{ partial:partial_a }}
{{ partial:partial_a }}
{{ noparse }}inside noparse{{ /noparse }}
{{ /partial:partial_a }}
{{ /partial:partial_a }}

{{ partial:partial_a }}
{{ partial:partial_a }}
{{ noparse }}inside noparse{{ /noparse }}
{{ /partial:partial_a }}
{{ /partial:partial_a }}

{{ partial:partial_a }}
{{ partial:partial_a }}
{{ noparse }}inside noparse{{ /noparse }}
{{ /partial:partial_a }}
{{ /partial:partial_a }}
EOT;

GlobalRuntimeState::$peekCallbacks[] = function ($processor, $nodes) {
NodeProcessor::$break = true;
};

$this->withFakeViews();
$this->viewShouldReturnRaw('partial_a', '{{ slot }}');

$actual = StringUtilities::normalizeLineEndings(trim($this->renderString($template)));

$occurrences = substr_count($actual, 'inside noparse');
$this->assertEquals(3, $occurrences, "Expected 'inside noparse' to appear exactly 3 times");
}
}