我在我的模型上添加了一个字段,用于指定缩略图应从何处裁剪,但我似乎无法将其添加到模板标签中。
这是我现在的做法:
{% if entry.main_image.crop_value == "center" %}
{% thumbnail entry.main_image.image "350x100" crop="center" as im %}
<a href="{{ entry.get_absolute_url }}"><img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}" alt=""></a>
{% endthumbnail %}
{% elif entry.main_image.crop_value == "top" %}
{% thumbnail entry.main_image.image "350x100" crop="top" as im %}
<a href="{{ entry.get_absolute_url }}"><img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}" alt=""></a>
{% endthumbnail %}
{% elif entry.main_image.crop_value == "bottom" %}
{% thumbnail entry.main_image.image "350x100" crop="bottom" as im %}
<a href="{{ entry.get_absolute_url }}"><img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}" alt=""></a>
{% endthumbnail %}
{% endif %}
这难道不是最好的方法吗?