0

I'm trying to dynamically load an image from a javascript file.

How I can load it using Assets (or FOSJsRoutingBundle) without having to paste my code of the .js file into the template?

1 Answer 1

4

you could post PHP generated JS variable and later use it in you JS files.

for example:

<script>
var image_path = '{{ asset('your/path/to/image') }}';
</script>

in case you need this path in the section, where typically JS files are included, you can always use twig blocks.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.