Yousuf Iqbal Hashim
Yousuf Iqbal Hashim

Reputation: 975

How to use bindings inside raw html?

How can one use dynamic attributes and bindings while rendering raw html. Suppose:

<script>
let name = 'Joseph'
let test = '<p>{name}</p>'
</script>

{@html test} <!-- Outputs: {name} instead of Joseph -->

I know, one would answer that, a better approach to this would be creating a component. But still I want to ask, if there is a way of using bindings inside raw html rendering?

Upvotes: 0

Views: 116

Answers (1)

Rich Harris
Rich Harris

Reputation: 29605

You can't. But you can do this: {@html `<p>${name}</p>`}

Upvotes: 5

Related Questions