1

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.

2 Answers 2

2

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"});
Sign up to request clarification or add additional context in comments.

Comments

2

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');

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.