Symfony\Bundle\TwigBundle\TwigEngine::render PHP 메소드

render() 공개 메소드

public render ( $name, array $parameters = [] )
$parameters array
    public function render($name, array $parameters = array())
    {
        try {
            return parent::render($name, $parameters);
        } catch (\Twig_Error $e) {
            if ($name instanceof TemplateReference) {
                try {
                    // try to get the real name of the template where the error occurred
                    $name = $e->getTemplateName();
                    $path = (string) $this->locator->locate($this->parser->parse($name));
                    if (method_exists($e, 'setSourceContext')) {
                        $e->setSourceContext(new \Twig_Source('', $name, $path));
                    } else {
                        $e->setTemplateName($path);
                    }
                } catch (\Exception $e2) {
                }
            }
            throw $e;
        }
    }

Usage Example

예제 #1
0
 /**
  * @Route("/contact", name="contact_route")
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function contactAction(Request $request)
 {
     /** @var AnonymousToken $token */
     $token = $this->tokenStorage->getToken();
     /** @var User $user */
     $user = $token->getUser();
     $contact = new Contact();
     if ($user !== 'anon.') {
         /** @var User $user */
         $contact->setEmail($user->getEmail());
         $contact->setUser($user);
     }
     $emailGetParam = $request->query->get('email');
     if (!empty($emailGetParam)) {
         $contact->setEmail($emailGetParam);
     }
     $form = $this->formFactory->createBuilder(FormType::class, $contact)->add('email', TextType::class, ['attr' => ['placeholder' => '*****@*****.**']])->add('message', TextareaType::class, ['attr' => ['maxlength' => 1000, 'rows' => 10]])->add('submit', SubmitType::class, ['label' => 'Envoyer'])->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->contactService->record($contact);
         $this->session->getFlashBag()->add(static::FLASH_BAG_EMAIL, $contact->getEmail());
         return new RedirectResponse($this->router->generate('confirmation_contact_route'));
     } else {
         return new Response($this->templating->render('base.html.twig', [TwigNodeTemplateTreeSection::TEMPLATE_TREE_BRANCH => 'contact', 'form' => $form->createView()]), $form->isSubmitted() ? Response::HTTP_BAD_REQUEST : Response::HTTP_OK);
     }
 }
All Usage Examples Of Symfony\Bundle\TwigBundle\TwigEngine::render