diff --git a/src/Compiler.php b/src/Compiler.php index dc447f5..f71e3e5 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -387,11 +387,14 @@ private function handleAttributeBinding(DOMElement $node) */ $templateStringContent = $matches['content']; - $templateStringContent = preg_replace( - '/\$\{([^}]+)\}/', - '{{ $1 }}', - $templateStringContent - ); + preg_match_all('/\$\{([^}]+)\}/', $templateStringContent, $matches, PREG_SET_ORDER); + foreach ($matches as $match) { + $templateStringContent = str_replace( + $match[0], + '{{ ' . $this->builder->refactorCondition($match[1]) . ' }}', + $templateStringContent + ); + } $dynamicValues[] = $templateStringContent; } else { @@ -404,7 +407,7 @@ private function handleAttributeBinding(DOMElement $node) } $node->setAttribute( - $name, + $name === 'src' ? Replacements::getSanitizedConstant('SRC_ATTRIBUTE_NAME') : $name, $this->implodeAttributeValue($name, $dynamicValues, $staticValues) ); } diff --git a/src/Models/Replacements.php b/src/Models/Replacements.php index d927cb2..01f8a7b 100644 --- a/src/Models/Replacements.php +++ b/src/Models/Replacements.php @@ -12,6 +12,7 @@ abstract class Replacements extends BasicEnum public const SMALLER = '<'; public const AMPERSAND = '&'; public const PIPE = '|'; + public const SRC_ATTRIBUTE_NAME = 'src'; /** * Removes all instances of replacements from target diff --git a/tests/fixtures/vue-bind/binding-with-template-string-3.twig b/tests/fixtures/vue-bind/binding-with-template-string-3.twig new file mode 100644 index 0000000..014c950 --- /dev/null +++ b/tests/fixtures/vue-bind/binding-with-template-string-3.twig @@ -0,0 +1,5 @@ +