Symfony 4 - VichUploader - 如何删除编辑表单中的图像预览?
Symfony 4 - VichUploader - How to remove image preview in edit form?
在我的项目 symfony 4 中,我实现了让我的用户拥有一个他们可以从他们的个人资料页面上传的头像的可能性,这要感谢 VichUploader。
为了显示他们当前的头像,我使用了 LiipImagineBundle。
除了因为我的树枝中的以下行:
<div class="form-row align-items-end">
<div class="col-md-5">{{form_row(form.avatar)}}
</div>
</div>
我有允许我 select 图片的 chamf,但我也有头像批发的预览,我不想要它。
而且我无法清除它。
或者目标是能够直接使用 LiipImagine 显示它,并在 {{form_row}} 中插入代码,这样我接下来就不必费心重新显示图像了像这样:
{% if user.avatar.imageName %}
<img src="{{ vich_uploader_asset(user.avatar, 'imageFile') | imagine_filter('avatar_big') }}" alt="">
{% endif %}
感谢您的帮助!
您可以覆盖所有 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
在我的项目 symfony 4 中,我实现了让我的用户拥有一个他们可以从他们的个人资料页面上传的头像的可能性,这要感谢 VichUploader。
为了显示他们当前的头像,我使用了 LiipImagineBundle。 除了因为我的树枝中的以下行:
<div class="form-row align-items-end">
<div class="col-md-5">{{form_row(form.avatar)}}
</div>
</div>
我有允许我 select 图片的 chamf,但我也有头像批发的预览,我不想要它。 而且我无法清除它。
或者目标是能够直接使用 LiipImagine 显示它,并在 {{form_row}} 中插入代码,这样我接下来就不必费心重新显示图像了像这样:
{% if user.avatar.imageName %}
<img src="{{ vich_uploader_asset(user.avatar, 'imageFile') | imagine_filter('avatar_big') }}" alt="">
{% endif %}
感谢您的帮助!
您可以覆盖所有 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