Skip to content

Instantly share code, notes, and snippets.

@Alphabetus
Last active December 12, 2020 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alphabetus/07bf3b01e646bd167002473fdaa7bbd6 to your computer and use it in GitHub Desktop.
Save Alphabetus/07bf3b01e646bd167002473fdaa7bbd6 to your computer and use it in GitHub Desktop.
Remote Requests Symfony - Render JS template asynchronously with Twig parameters
<?php
/**
* @Route("/test.js", name="app.test")
*/
public function test()
{
$optionalParams = array('foo'=>'bar');
$renderedView = $this->renderView("test.js.twig");
$resp = new Response($renderedView, $optionalParams);
$resp->headers->set('Content-Type','text/javascript');
return $resp; // this triggers the file test.js.twig with working JS out of it.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment