diff --git a/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php b/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php index 37bc59b2..5d5c314a 100644 --- a/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php @@ -38,7 +38,7 @@ parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterfa if (is_iterable($vars)) { $content = strings($content)->{'append'}(...$vars)->toString(); } else { - $content = strings($content)->{'append'}($vars)->toString(); + $content = strings($content)->{'append'}($vars[0])->toString(); } } @@ -46,7 +46,7 @@ parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterfa if (is_iterable($vars)) { $content = strings($content)->{'prepend'}(...$vars)->toString(); } else { - $content = strings($content)->{'prepend'}($vars)->toString(); + $content = strings($content)->{'prepend'}($vars[0])->toString(); } } @@ -149,6 +149,13 @@ parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterfa if ($key == 'firstSegment') { $content = strings($content)->{'firstSegment'}(isset($vars[0]) ? (string) $vars[0] : ' ')->toString(); } + + if ($key == 'format') { + $formatVars = isset($vars[0]) ? explode($itemsDelimeter, $vars[0]) : []; + if (count($formatVars) > 0) { + $content = strings($content)->{'format'}(...$formatVars)->toString(); + } + } } return (string) $content; diff --git a/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php index 7a869ed2..60d55e0b 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php @@ -98,4 +98,7 @@ test('[strings] shortcode', function () { // firstSegment $this->assertEquals("SG-1", parsers()->shortcodes()->parse('[strings firstSegment]SG-1 returns from an off-world mission[/strings]')); $this->assertEquals("SG", parsers()->shortcodes()->parse('[strings firstSegment="-"]SG-1 returns from an off-world mission[/strings]')); + + // format + $this->assertEquals("There are 5 monkeys in the tree", parsers()->shortcodes()->parse('[strings format=5,tree]There are %d monkeys in the %s[/strings]')); }); \ No newline at end of file