Last active
December 12, 2020 23:50
-
-
Save Alphabetus/07bf3b01e646bd167002473fdaa7bbd6 to your computer and use it in GitHub Desktop.
Remote Requests Symfony - Render JS template asynchronously with Twig parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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