Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

CSS attribute (background-image) from Odoo Backend

By
Md. Tanzilul Hasan Khan
on 10/21/16, 3:05 AM 310 views

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

1
shameem@aχoncoms
On 10/27/16, 2:48 AM
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  ! 


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/21/16, 3:05 AM
Seen: 310 times
Last updated: 10/27/16, 6:48 AM