Home > Software design >  How to create a redirect to an html file in a php condition on symfony?
How to create a redirect to an html file in a php condition on symfony?

Time:05-17

how to create a redirect to an html file in a php condition on symfony please? I want that if the counter is greater than 4 there is a redirection to an html page.

if (count > 4){
// Redirect html file  (add html file example.html.twig)
}

CodePudding user response:

Try this one

if (count > 4){
$script = "<script> window.location = 'example.html.twig';</script>";
echo $script;
}

CodePudding user response:

If you simply want to render a html twig template from symfony you can use the following in your Controller:

  return $this->render('index.html.twig');
  

https://symfony.com/doc/current/templates.html#rendering-a-template-in-controllers

If you want to redirect to an external URL:

return $this->redirect('http://stackoverflow.com');

https://symfony.com/doc/current/controller.html#redirecting

  •  Tags:  
  • php
  • Related