Access variables from Server
chmich opened this issue · comments
Christian commented
How do you access variables from server?
Inertia docs showes it by erb (<%= var %>)
But, i cannot name my file to something like index.svelte.erb
.
Brandon Shar commented
Hey @chmich , view
variables are only in rails views. If you want to access data in your svelte components, you'd want to pass it as props.
Christian commented
Thanks, Brandon, found it
i had to export the variable from the svelte script
Controller
render inertia: 'svelte/index', props: { backend_var: 'Backend' }
Svelte
<svelte:head>
<title>Hello {backend_var}</title>
</svelte:head>
<script>
export let backend_var
</script>