[FIXED] How to pass a Jinja variable inside a Svelte component (Django/Flask)

Issue

I have a Flask app and I need to pass a variable called var to the Svelte component App.Svelte

In HTML it does {{ var }} but it confuses Svelte because it uses { } as a delimiter and says var says it's not defined. Vue allows Jinja to define different delimiters (like []) to solve this problem, but I haven't been able to find a way to do that in Svelte.

How do I pass variables to Svelte?

Solution

I do it like this:

    <script>
        var variable = "{{your_django_variable}}";
    </script>

Just make sure you're loading it before loading Svelte

Answered By - lucutzu33

Answer Checked By - Cary Denson (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published