2016-11-25 112 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

当然并非如此。 –