Question

I want to load a specific thumbnail for an article using Twig and Assetic. Here is the code that doesn't work:

in config and params:

thumbnail_dir="/Resources/public/images/article_thumbs"

twig:
    debug:             %kernel.debug%
    strict_variables: %kernel.debug%
    globals:
        thumbnail_dir: %thumbnail_dir%

In the twig file:

{% image '@MyMainBundle' ~ thumbnail_dir ~ '/' ~ id ~ '/' ~ article.thumbnailFile %}
    <img src="{{ asset_url }}"
         alt="{{ article.title }}" />
{% endimage %}

So basically I have images I'm storing in /Resources/public/images/article_thumbs/{ID}/{FILE.ext}

I want to get those for a specific article in Twig. How can I achieve that?

EDIT: Why am I not putting them in the web folder?

I guess I had thought about using Assetic filters at some point, but I suppose there is really no need.

I'll just store them in the web folder for now.

So if I make thumbnail_dir="/images/article_thumbs" and put that in the web dir, Do I just say {{ asset( thumbnail_dir ~ '/' ~ id ~ '/' ~ article.thumbnailFile ) }} in twig?

Was it helpful?

Solution

According to Kriswallsmith this is not possible using assetic.

https://github.com/kriswallsmith/assetic/issues/60

If I understood correctly: Since assetic does not render the Twig the variable is not being read.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top