To an image in the "src" I have to put a varibale path, when I do that in the twig, the resulting url is invalid, which leads me to use asset () to be correct, but it does not work because says that variable with the path does not exist.
What I now want to do is to use the same function of asset () but in the controller, so the correct resulting url in the controller send to html.twig
It is in this way that I send the path, in a json and with jquery I add the src attribute to the image
$path=$promocion->getImagen()->getEnlace()['path'];
$detallesdeproductos[0]["path"]=$path;
$response = new Response(json_encode($detallesdeproductos));
$response->headers->set('Content-Type', 'application/json');
return $response;