1

I am trying to display image from facebook profile.

routing.yml

_graph_facebook:
path: graph.facebook.com/{fbId}/{var}
requirements:
    _scheme:  https

template.html.twig

What I get is htpps://mydomain.local/graph.facebook.com/facebookId/picture .

I was trying with assets but it works only if it's hardcoded.

{% image 'https://graph.facebook.com/'~app.user.facebookId~'/picture'%}
        <img src="{{ asset_url }}" alt="Example" />
{% endimage %}

This code doesn't work it says that: Unexpected token "operator" of value "~". I couldn't find answer probably it's vaery simply.Thanks for Your help

Dalli
  • 64
  • 2
  • 11

3 Answers3

0

You can't use routing for external URI management only internal.

If you want to encapsulate this "behavior" in a method/function accessible by twig i can suggest you to create a Twig_Method via an custom twig extension : http://symfony.com/doc/current/cookbook/templating/twig_extension.html

Fabien MEYNARD
  • 597
  • 4
  • 12
0

As said in the comments, the router only applies to the URLs of your website.

Anyway, you can simply display the image with the facebookId value:

<img src="https://graph.facebook.com/{{ app.user.facebookId }}/picture" alt="Example" />
A.L
  • 10,259
  • 10
  • 67
  • 98
  • Thank You. I just saw somewhere in documentation a tip - good practice about routing shouldn't be hard-coded in template. But now it's clear.thanks – Dalli Jan 06 '14 at 15:05
0

Concatenation operator's ~ arguments should be space-char separated.

'https://graph.facebook.com/' ~ app.user.facebookId ~ '/picture'

External urls should be escaped with html_attr filter:

<img src="{{ asset_url|e('html_attr') }}" alt="Example" />
Dmitriy Sintsov
  • 3,821
  • 32
  • 20