0

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?

Yousuf Iqbal Hashim
  • 925
  • 1
  • 11
  • 21
  • Maybe this can help you: https://stackoverflow.com/questions/50300176/is-it-possible-to-dynamically-load-a-svelte-template-at-runtime. Or you can do something like this: – knobo Jul 07 '19 at 18:34

1 Answers1

5

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

Rich Harris
  • 28,091
  • 3
  • 84
  • 99