Skip to content

Commit 1f8a34f

Browse files
committed
Add support for Javascript expressions in v-html attributes
`v-html` attributes currently only support direct references to top-level variables in the template data. Use the Peast Javascript expression parsing support to make it possible to evaluate expressions in `v-html` attributes. Bug: T396098
1 parent 5b6318a commit 1f8a34f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Component.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ private function handleRawHtml( DOMNode $node, array $data ) {
319319
$variableName = $node->getAttribute( 'v-html' );
320320
$node->removeAttribute( 'v-html' );
321321

322-
$this->appendHTML( $node, $data[$variableName] );
322+
$this->appendHTML( $node, $this->app->evaluateExpression( $variableName, $data ) );
323323
}
324324
}
325325

tests/php/TemplatingTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ public function testTemplateWithVhtmlVariable_ReplacesVariableWithGivenValue() {
102102
$this->assertSame( '<div><div><p>some value</p></div></div>', $result );
103103
}
104104

105+
public function testTemplateWithVhtmlVariableNestedData_ReplacesVariableWithGivenValue() {
106+
$result = $this->createAndRender(
107+
'<div><div v-html="value.html"></div></div>',
108+
[ 'value' => [ 'html' => '<p>some value</p>' ] ]
109+
);
110+
111+
$this->assertSame( '<div><div><p>some value</p></div></div>', $result );
112+
}
113+
105114
public function testTemplateWithVhtmlVariableAndAttributeBinding_ReplacesBoth(): void {
106115
$result = $this->createAndRender(
107116
'<div><div :data-a="a" v-html="html"></div></div>',

0 commit comments

Comments
 (0)