2

I have some javascript files in my Symfonyt2 project that load some reources dynamically from the javascript file.
for example:

$('.records_list').DataTable({
    "language": {
        "url": "../shared/js/datatables.persian.json"
    }
});

the url ../shared/js/datatables.persian.json works in pages with url like /test but in pages with url ike /test2/action it fails.
How can i fix this?
Is there a tool like cssrewrite filter for assetic?
or can I make routes for such urls?

2
  • 2
    Did you try: "url": "/shared/js/datatables.persian.json"? Commented Nov 4, 2014 at 22:40
  • @dfsq: this is related to domain but I need to move the pages to different folders so I dont want to change all of these on every move Commented Nov 4, 2014 at 23:33

1 Answer 1

1

If you do not have too many cases like this, you can store your file path with twig in a hidden div for example :

<div id="file-store" style="display:none;" data-value="{{ asset('shared/js/persian.json') }}"></div>

And retrieve it in js :

var sharedFile = $('#file-store').attr('data-value');
$('.records_list').DataTable({
    "language": {
        "url": sharedFile
    }
});

If you have a lot of cases like this, then you can make use of the FOSJsRoutingBundle :

https://github.com/FriendsOfSymfony/FOSJsRoutingBundle

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.