0

There already exist similar questions (concatenation in twig, concatenation in Assetic), but it is not helping me.

I am trying to display an image from the path and image name passed from controller:

{% image 'bundles/index/uploads/logos/' ~ fileName %}
<img src="{{ asset_url }}" />
{% endimage %}

And I am getting an error:

Unexpected token "operator" of value "~"

How to overcome this issue? It seems that concatenation is not allowed in {% image %}

P.S.

<img src="{{ asset('bundles/index/uploads/logos/' ~ university.getLogo) }}" />

This works fine, but I am up to Assetic due filter and output management.

Community
  • 1
  • 1
Ignas Damunskis
  • 1,515
  • 1
  • 17
  • 44

1 Answers1

0

You should define your image filter as a Twig function & when use it. For example (code used from documenation)

# app/config/config.yml
assetic:
  filters:
      jpegoptim:
          bin: path/to/jpegoptim
  twig:
      functions:
          jpegoptim: ~

In your twig template:

<img src="{{ jpegoptim('@AppBundle/Resources/public/images/' ~ fileName) }}" alt="Example"/>

You can find more info in Symfony documentation: http://symfony.com/doc/current/assetic/jpeg_optimize.html#shorter-syntax-twig-function

Aurimas
  • 770
  • 9
  • 14