Skip to content

Commit

Permalink
Add antlers modifier (#6489)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga authored Aug 12, 2022
1 parent 294b5de commit 2fd7d5b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Modifiers/CoreModifiers.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ public function ampersandList($value, $params)
return Str::makeSentenceList($value, $glue, $oxford_comma);
}

/**
* Parses the value as an Antlers template.
*
* @param mixed $value
* @param array $params
* @return string
*/
public function antlers($value, $params, $context)
{
return (string) Antlers::parse($value, $context);
}

/**
* Alias an array variable.
*
Expand Down
21 changes: 21 additions & 0 deletions tests/Modifiers/AntlersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Tests\Modifiers;

use Statamic\Modifiers\Modify;
use Tests\TestCase;

class AntlersTest extends TestCase
{
/** @test */
public function it_parses_as_antlers(): void
{
$modified = $this->modify('foo {{ foo }} bar {{ bar }}', ['foo' => 'alfa', 'bar' => 'bravo']);
$this->assertEquals('foo alfa bar bravo', $modified);
}

private function modify($value, array $context = [])
{
return Modify::value($value)->context($context)->antlers()->fetch();
}
}

0 comments on commit 2fd7d5b

Please sign in to comment.