vichuploaderbundlesymfony6

Vichuploader Bundle And Background-image


I am using Vichuploader to upload the photos of a category, the problem is that I need to retrieve the image from the css . Background-image and I don't know how to implement the code here.

{{asset ('images/services/')}}{{category.image}} for html template but css ?? style="background-image:url(images/services/image.jpg);"

Help me please.! enter image description here

I am trying this suggestion :

 <div class="row">
        {% for  category in categories %}
        <div class="col-md-6 col-lg-6 ftco-animate">
            <div class="block-7">
                <div class="img prix"
                 style="background-image: url('{{ 
           vich_uploader_asset(category, 'image') }}')">
                </div>
            </div>
        </div>
        {% endfor %}
</div>

but i have this error : enter image description here

My Html have this error too: enter image description here

My Code : enter image description here

enter image description here

enter image description here


Solution

  • You can use vich_uploader_asset() in a twig file to generate the url for your image:

    <div class="img prix" 
         style="background-image: url('{{ vich_uploader_asset(category, 'imageFile') }}')"
    ></div>
    

    This twig function is documented here