Reputation: 4130
Within my Symfony2 application, in order to link to other pages, I've generated the href value using the path Twig function.
I maybe wrong but I think I previously read about a JavaScript equivalent but can't seem to find it now. I am generating some html using JavaScript and want to know if its possible to generate the href values to other pages within the application using purely JavaScript.
Appreciate any advice.
Upvotes: 1
Views: 93
Reputation: 10890
I would recommend using FosJsRoutingBundle.
Lets assume an action of controller:
/**
* @Route("/indx/", options={"expose"=true}, name="indexRoute")
* @Template()
*
* @return array
*/
public function indexAction()
{
(...)
}
options={"expose"=true}
is what is important here.
Now js equivalent of path
call is just:
Routing.generate('indexRoute');
Upvotes: 2
Reputation: 2123
You are probably looking for this bundle: https://github.com/FriendsOfSymfony/FOSJsRoutingBundle
Then you can do this kind of stuff in javascript:
Routing.generate('my_route', {"my":"param"});
Upvotes: 2