简体   繁体   中英

Symfony/Twig - styling form widgets

I'm trying to make an ugly file upload button look like a nice font awesome icon.

Here is what I have so far:

<div class="col-12 col-md-4">
    <button type="button" class="btn btn-round mt-0 mb-0 uploadMediaTrigger" data-toggle="modal" data-target="#uploadMedia" rel="tooltip" data-placement="top" title="Upload Media">
        <i class="far fa-images"></i>
    </button>
    {{ form_widget(postForm.file, { 'attr': {'class': 'far fa-images'} } ) }}
</div>

Do you know how I can get the ugly button to look like the font awesome icon? Seems like merely adding the font awesome classes doesn't work.

Here is a picture:

在此处输入图片说明

Check this answer with Form Themes and Form Extensions. This solution is compatible with Symfony 2.8.x and 4.x.

Can I put html inside a Symfony form button with Twig?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM