inertiajs / inertia-rails

The Rails adapter for Inertia.js.

Home Page:https://inertiajs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Access variables from Server

chmich opened this issue · comments

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.

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.

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>