I have a table Movie :
1. id
2. title
3. content
4. links_id (foreign key)
And i have a table Links:
1. id
2. name
3. url
And i have page index.html.twig :
{% for link in movie.links %}
<a href="#{{ link.url }}" >{{ link.url }}</a>
{% endfor %}
I would like to view the url linked table by the movie and that allowed me to redirect to a site based on the URL. For example i have some data in Table Links :
id:1 name : webSite1 url : www.webSite1.com
id:2 name : webSite2 url : www.webSite2.com
And i have some data in table Movie :
id : 1
title : title1
content : content1
links_id : 1
when I would dispaly a movie with the links i try with this :
{% for link in movie.links %}
<a href="{{ link.url }}" >{{ link.url }}</a>
{% endfor %}
when I click on www.webSite1.com it appears to me that url :
http://localhost/download/web/app_dev.php/downloads/Movie/show/www.webSite1.com
I would to redirect in : www.webSite1.com
You need to add the schemes to your url.
<a href="http://{{ link.url }}" >{{ link.url }}</a>
If you want to render an absolute url in twig you want to be using the url()
function. http://symfony.com/doc/current/reference/twig_reference.html#url
The path()
function generates a relative url. http://symfony.com/doc/current/reference/twig_reference.html#path
Complementing to Federkun, other solution is to maintain your original code
{% for link in movie.links %}
<a href="{{ link.url }}" >{{ link.url }}</a>
{% endfor %}
But in your database the url should be complete like
id:1 name : webSite1 url : http://www.webSite1.com
id:2 name : webSite2 url : http://www.webSite2.com
I thought this is better because several websites only recognize "https" protocol