1

I want to realize the following thing: in my parameters.yml I have uploads_url: http://test.site.com. It's a URL to Docker container with my images. Next, I have an entity with names of this pictures.

I want to generate URL in twig like this:

background-image: url({{ 'URL from parameters' + 'name of picture from `entity`' }})

At present time I have the second part of the previous expression (name of the picture). How can I generate the 1st part?

1 Answer 1

2

app/config/config.yml

# Twig Configuration
twig:
    globals:
        url: "%url%"

app/config/parameters.yml

parameters:
    url: 'your_url'

official doc How to Inject Variables into all Templates (i.e. global Variables)

twig concatenate How to concatenate strings in twig

Sign up to request clarification or add additional context in comments.

1 Comment

Are there any variants to do it without "twig globals"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.