Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
9225 Lượt xem

I have a custom field which stores image in backend. I want to show that image as background image of a section on website.

The css is - background-image:url("custom_image.jpg"); [currently static]

How can I get  the image custom_image field image from backend to website css or style?

Thanks

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

if you dont need to use js you can directly give like this,

t-attf-style="background-image: url({{'data:image/png;base64,%s' % company.logo.decode('utf-8')}});"

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
You can solve your problem using following steps

Step 1: Create a Javascript File and call a python function when document is ready.

$(document).ready(function () {
//Call a Python function
//
});

Use what I explained you earlier  : https://www.odoo.com/forum/help-1/question/odoo-9-website-js-help-109603#answer-109604

Step 2: Return value of Image field in python function 

Step 3: Set Background image using JQuery.

Example

(new Model('your.model')).call('your_function').then(function (your_return_value) { 
     var image_format = 'url("data:image/gif;base64,'+ your_return_value +'")'
     //SET BACKGROUND IMAGE LIKE
     $(".oe_leftbar").css("background-image", image_format);
 });

All the Best  ! 


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 10 16
3672
1
thg 1 17
3687
1
thg 12 24
2182
2
thg 8 20
3971
1
thg 3 15
5980