【问题标题】:Symfony 4 - VichUploader - How to remove image preview in edit form?Symfony 4 - VichUploader - 如何删除编辑表单中的图像预览?
【发布时间】:2019-09-15 17:09:24
【问题描述】:

在我的项目 symfony 4 中,我实现了让我的用户拥有一个他们可以从他们的个人资料页面上传的头像的可能性,这要感谢 VichUploader。

为了显示他们当前的头像,我使用了 LiipImagineBundle。 除了因为我的树枝中有以下一行:

<div class="form-row align-items-end">
            <div class="col-md-5">{{form_row(form.avatar)}}
            </div>
        </div>

我有允许我选择图像的 chamf,但我也有头像批发的预览,我不想要它。 而且我无法清除它。

或者目标是能够直接使用 LiipImagine 显示它,并在 {{form_row}} 中插入代码,这样我就不必费心在它旁边重新显示图像,如下所示:

{% if user.avatar.imageName %}
            <img src="{{ vich_uploader_asset(user.avatar, 'imageFile') | imagine_filter('avatar_big') }}" alt="">
        {% endif %}

感谢您的帮助!

【问题讨论】:

    标签: php image symfony vichuploaderbundle liipimaginebundle


    【解决方案1】:

    您可以为所有 Vich 图像字段或仅此一个覆盖表单字段模板。要更改所有 Vich 图像字段的模板,请将其包含在您的表单主题中:

    {%- block vich_image_widget -%}
        <div class="vich-image">
            {{- form_widget(form.file) -}}
            {%- if form.delete is defined -%}
                {{- form_row(form.delete) -}}
            {%- endif -%}
            {# REMOVE THE BLOCK BELOW TO REMOVE IMAGE OR DOWNLOAD LINKS#}
            {%- if image_uri -%}          
                <a href="{{ asset_helper is same as(true) ? asset(image_uri) : image_uri }}"><img src="{{ asset_helper is same as(true) ? asset(image_uri) : image_uri }}" alt="" /></a>
            {%- endif -%}
            {%- if download_uri -%}
                <a href="{{ asset_helper is same as(true) ? asset(download_uri) : download_uri }}">{{ translation_domain is same as(false) ? download_label : download_label|trans({}, translation_domain) }}</a>
            {%- endif -%}
        </div>
    {%- endblock -%}
    

    原始文件: https://github.com/dustin10/VichUploaderBundle/blob/master/Resources/views/Form/fields.html.twig

    查看 symfony 网站了解如何使用自定义表单主题: https://symfony.com/doc/4.1/form/form_customization.html

    【讨论】:

      猜你喜欢
      • 2021-07-27
      • 2020-02-03
      • 2021-04-08
      • 1970-01-01
      • 2014-12-25
      • 1970-01-01
      • 2015-07-07
      • 1970-01-01
      • 2017-12-29
      相关资源
      最近更新 更多