I want to concatenate javascript variable within blade {{ curly braces }}
as following:
Currently:
ajax: "{{ route(api.colors) }},"
What I want:
var page='colors';
...
ajax: "{{ route(api."+page+") }},"
Is it possible?
You cannot do this directly because the curly brackets are rendered on the server and javascript runs on the client side. You could put a placeholder in you route and then replace this part in your javascript code. Like so:
// Imagine the `api.page` route value is `/controller/{page}`:
ajax: "{{ route(api.page) }}".replace("{page}", page);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With