简体   繁体   中英

jquery load function with a twig template file

i'm trying to load a twig file template with the load() function of jquery. But i don't know how to write the path for the template .

Is it like this ?

htmlObject.load("LeymaxDashboardBundle:AdminPlaine:aucun.html.twig");

thank you in advance.

You should create an controller that will return template content. Then use FOSJsRoutingBundle to approach its route from jQuery.

The jQuery.load function expects a valid URL to sent the request to.

So you need to create the URL to a controller and pass it into the jQuery function

{{  path('route_name') }}

Inside the action of the controller you can proceed in different ways. Handle the logic you want to achieve and return a Response that matches your needs.

  • create a JSON response with partial data

return new JsonResponse(array('success' => true));

  • create a normal response with a twig template reference

return $this->render('MyProjectMyBundle:ControllerName:template.html.twig');

i have a idea you can try...In your Controller

 public function someAction()
 {
    return $this->render('LeymaxDashboardBundle:AdminPlaine:aucun.html.twig');
 }

configure in routing.yml

Jquery

 load("{{path('the route')}}");

of course this is just my idea, i don't kown if it will work.you can try...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM