如何使用twig渲染方法返回带有javascript方法的html

时间:2014-02-18 12:03:22

标签: javascript symfony twig

我想在点击按钮时渲染控制器我使用这个javascript方法

function getPopoverContent(input) {   
   return {{ render(controller("LeymaxReserveBundle:Reserve:showAddReserveModal",{'iduser': user.id,'token':'1238','idreserve':'0'})) }};

    }

但它会导致非法异常,引号::

也是如此
 return "{{ render(controller("LeymaxReserveBundle:Reserve:showAddReserveModal",{'iduser': user.id,'token':'1238','idreserve':'0'})) }}";

这是我的acion ::

public function showAddReserveModalAction($iduser, $token, $idreserve) {

        $em = $this->getDoctrine()->getManager();
        $user = $em->getRepository('LeymaxContactBundle:User')->find($iduser);

        return $this->render('LeymaxReserveBundle:Reserve:addReserveModal.html.twig',       array(
                    'user' => $user,
                    'token' => $token,

        ));
    }

怎么办?

1 个答案:

答案 0 :(得分:0)

你应该使用:

 return "{{ render(controller('LeymaxReserveBundle:Reserve:showAddReserveModal',{'iduser': user.id,'token':'1238','idreserve':'0'})) }}";

你现在正在分解你的javascript:

return "aaaa"bbbb"aaaa"; <-- invalid syntax