2016-11-25 104 views
0

我已經創建了自定義的最新博客模板。但我無法在縮略圖中顯示封面圖片。Odoo博客封面圖片不顯示

封面圖片應該是在這裏:

enter image description here

我已經寫了下面的代碼顯示封面圖片:

<div class="panel"> 
    <t t-set="properties" t-value="json.loads(post.cover_properties)"> 
     <a class="o_panel_cover" t-attf-href="#{blog_url('', ['blog', 'post'], blog=post.blog_id, post=post)}" t-att-style="background-image: #{cover_properties.get('background-image')};"> 
     </a> 
    </t> 
    <div class="panel-heading mt0 mb0"> 
     <h4 class="mt0 mb0"> 
      <a t-attf-href="#{blog_url('', ['blog', 'post'], blog=post.blog_id, post=post)}" t-field="post.name"></a> 
      <span t-if="not post.website_published" class="text-warning"> 
      <span class="fa fa-exclamation-triangle ml8" title="Unpublished"/> 
      </span> 
     </h4> 
    </div> 

寫代碼的形象不加載,它後如下所示:

enter image description here

如何顯示圖像?

+0

也如果鍵入以下內容: ' t-attf-style =「background-image:#{cover_properties.get('background-image')};」' 它說,沒有類型的對象沒有attrubute get。 –

回答

0

首先,控制器有幾件事。

最新帖子路線不使蓋的屬性,它是象下面這樣:

return request.render("website_blog.latest_blogs", { 
     'posts': posts, 
     'pager': pager, 
     'blog_url': blog_url, 
    }) 

所以我在我的控制器中添加必要的功能和返回是這樣的:

return request.render("website_blog.latest_blogs", { 
     'posts': posts, 
     'pager': pager, 
     'blog_url': blog_url, 
     'blogs':blogs, 
     'blog_posts': blog_posts, 
     'blog_posts_cover_properties': [json.loads(b.cover_properties) for b in blog_posts], 
    }) 

在XML這樣的返回:

<t t-set="cover_properties" t-value="blog_posts_cover_properties[post_index]"/> 
    <a class="o_panel_cover" t-attf-href="#{blog_url('', ['blog', 'post'], blog=post.blog_id, post=post)}" 
     t-attf-style="background-image: #{cover_properties.get('background-image')};"></a> 
0

我會建議你清除瀏覽器的緩存,有時是因爲緩存超載我們沒有得到圖像。

+0

當然並非如此。 –