跳至内容
菜单
此问题已终结
6 回复
12414 查看

Template "Product" contain this code:

span itemprop="image" t-field="product.image" t-field-options="{"widget": "image", "class": "product_detail_img shadow"}"

And result rendered page contian this:

img class="img img-responsive product_detail_img shadow" src="/website/image/product.template/21826_c5f8c53/image" style="" 

How I can "alt" attribute for img tag?


形象
丢弃
最佳答案


You can use t-att-attribute_name to add an attribute try like:

<span itemprop="image" t-field="product.image" t-att-alt="product.name" t-field-options="{"widget": "image", "class": "product_detail_img shadow"}" ></span>

Edit:

Even if "alt" attribute is added you won't be able to see it on form, because on form it is never a case when there is no image, when you upload an image or give a wrong src for image(which doesn't exist) Odoo replaces that image to a default image which resides in "/web/static/src/img/placeholder.png" but it works well in Reports.
形象
丢弃
编写者

When added t-att-alt=”product.name” got the 500 error Error message: 'ascii' codec can't decode byte 0xd0 in position 23: ordinal not in range(128)

IMHO it is because the product is used.name in Russian. Tried to add the t-att-alt=”product.name” Received: That is, the attribute is not added neither span nor in img
编写者

When added t-att-alt=”product.name” got the 500 error Error message: 'ascii' codec can't decode byte 0xd0 in position 23: ordinal not in range(128) span itemprop="image" t-field="product.image" t-att-alt="product.name" t-field-options="{"widget": "image", "class": "product_detail_img shadow"}"/ IMHO it is because the product is used.name in Russian. Tried to add the t-att-alt=”product.name” Received: span itemprop="image" data-oe-model="product.template" data-oe-id="21259" data-oe-field="image" data-oe-type="image" data-oe-expression="product.image" data-oe-translate="0" img class="img img-responsive product_detail_img shadow" src="/website/image/product.template/21259_21735ca/image" style="" /span That is, the attribute is not added neither span nor in img

最佳答案

This works fine for me:

<span itemprop="image" t-field="bride.img_scaled_w400" t-options="{'widget': 'image', 'style':'maxwidth: 400px', 'alt-field': 'kco_alt'}" t-att-alt="bride.kco_alt" />

The alt attribute is returned in both the span and the img tags.  

形象
丢弃
最佳答案

If you want to add alt attribute for seo porposes. Add attribute alt-field in t-options.

 <span itemprop="image" t-attf-content="{{request.httprequest.url_root}}web/image/trending.template/{{trending.id}}/image" t-field="trending.image" t-options="{'widget': 'image','alt-field': 'name'}" t-att-alt="trending.name" />



形象
丢弃
最佳答案

thanks for the tip but as the alt attribute is included between span tags (and not img tags) this is not usefull for seo purposes

形象
丢弃
相关帖文 回复 查看 活动
0
10月 24
833
4
3月 22
17305
2
12月 21
1802
0
10月 21
2938
2
12月 19
23489