Home » PHP » Twig » How AJAX calls work with TWIG

How AJAX calls work with TWIG

Twig can load a template through AJAX.. The following details are below


namespace AppBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class DefaultController extends FrontendController {
     * Fetch data from ajax call.
     * @param Request $request    
     * @Route("/xyz/{id}", methods={"GET"})
    public  function proAjaxAction(Request $request){   
      $this->view->id = $request->get('id');


    resource: "@AppBundle/Controller/"
    type:     annotation
    prefix:   /


{% do pimcore_head_script().captureStart() %} 
function A(){
url:'/xyz/{{ parameterVal }}',
success : function(response){
{% do pimcore_head_script().captureEnd() %}


{{ id }}

Check Also

Top Twig Template Interview And Answer Part 5

1.How can we loop the array in twig template? {% for item in test %} …

Leave a Reply

Your email address will not be published. Required fields are marked *