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
12 changes: 11 additions & 1 deletion src/View/Antlers/Language/Runtime/NodeProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
use Statamic\View\Cascade;
use Statamic\View\Slot;
use Statamic\View\State\CachesOutput;
use Stringable;
use Throwable;

class NodeProcessor
Expand Down Expand Up @@ -1802,7 +1803,9 @@ public function reduce($processNodes)
$output = RuntimeValues::resolveWithRuntimeIsolation($output);
}

$output = PathDataManager::reduceForAntlers($output, $this->antlersParser, $this->getActiveData(), $node->isClosedBy != null);
if (! $this->interpolatingAugmentable($output)) {
$output = PathDataManager::reduceForAntlers($output, $this->antlersParser, $this->getActiveData(), $node->isClosedBy != null);
}
}

if ($this->isInterpolationProcessor) {
Expand Down Expand Up @@ -2512,6 +2515,13 @@ public function reduce($processNodes)
return $buffer;
}

private function interpolatingAugmentable($output): bool
{
return $this->isInterpolationProcessor
&& $output instanceof Augmentable
&& $output instanceof Stringable;
}

/**
* Executes any PHP within the provided buffer and returns the result.
*
Expand Down
22 changes: 22 additions & 0 deletions tests/Antlers/Runtime/TagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Tests\Antlers\Runtime;

use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Statamic\Facades\Asset;
use Statamic\Facades\AssetContainer;
use Statamic\Tags\Tags;
use Tests\Antlers\ParserTestCase;

Expand Down Expand Up @@ -46,4 +50,22 @@ public function index()

$this->assertSame('b', $this->renderString('{{ test_tag }}{{ a }}{{ /test_tag }}', [], true));
}

/**
* @see https://github.com/statamic/cms/issues/11257
*/
public function test_objects_returned_from_tags_keep_their_data_when_assigned_to_a_variable()
{
Storage::fake('test', ['url' => '/assets']);
Storage::disk('test')->put('a.jpg', UploadedFile::fake()->image('a.jpg')->getContent());
tap(AssetContainer::make('test')->disk('test'))->save();
Asset::find('test::a.jpg')->data(['alt' => 'Alpha'])->save();

$template = <<<'EOT'
{{ img = { asset url="/assets/a.jpg" } }}
{{ img }}|{{ img.url }}|{{ img.alt }}|{{ img:alt }}
EOT;

$this->assertSame('/assets/a.jpg|/assets/a.jpg|Alpha|Alpha', trim($this->renderString($template, [], true)));
}
}
Loading