Answer the question
In order to leave comments, you need to log in
How to make a redirect in Twig template engine?
Hello, I have a Twig templating engine on my site. The page displays a link from the database in the form {{post.link}}. How to make a redirect happen? In bare php, the script looks like this:
<?php
header("Location: http://vk.com");
?>
Answer the question
In order to leave comments, you need to log in
Another plus of Twig is that if a developer wants to do something where there is no place for it, then he will have problems with it.
You shouldn't do this in templates. Generally. If you really want it, you can:
<script>
window.location = {{post.link | json_encode()}};
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question