0
votes

I'm using Symfony 5 and the Vich uploader bundle for uploading images, and I have a separate React app within the project that handles the images. The image directory and path created by Vich Uploader config and can be access within the Symfony environment. But I don't know how to pass that url path into my React app.

My React app is connected using the Symfony document with a twig template.

show_image.twig.html

<div id="root"></div>

{% block javascripts %
    {{ encore_entry_script_tags('app') }}
{% endblock %}

app.js

ReactDOM.render(<App/>, document.getElementById('root'));

Can I get the path into my React app without hardcoding them in?

1

1 Answers

0
votes

The easiest way to pass data in your front is to store the data in a var in your twig like this:

<div id="root"></div>

{% block javascripts %
    <script>
        var imagePath = '{{ image_path }}';
    </script>
    {{ encore_entry_script_tags('app') }}
{% endblock %}