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.

0

How to use varibales in <t t-foreach tag

By
Cyrus Waithaka
on 4/19/15, 5:21 PM 1,643 views

I am trying to add a slideshow to the product.template form view. In this, I want to show all images related to a product as a slideshow on the backend.

I have managed to create the product.image class and created the one2many relationship successfully as follows.


class product_product(osv.Model): _inherit = "product.template" _columns = { 'images': fields.one2many( 'product.images', 'product_id', 'Product Images' ) }

I however have a problem displaying the list of images using a <t-foreach tag. Here is the part of the view that I am adding to the product.product_template_form_view view.

 <div class="slider project-slider slider-for">
<t t-foreach="record.images" t-as="i"> 
<div><span t-field="i.image" class="img-responsive" t-field-options="{"widget": "image", "class": "img-responsive"}"/></div>
</t>
</div>

I suppose the line <t t-foreach="record.images" ...... is not fetching the current product object. How to I make it to iterate through the "images" field of the current record?

Here is the full xml file

        <record id="view_product_form_img" model="ir.ui.view">
<field name="name">product.product.images</field>
<field name="model">product.template</field>
<field name="priority">3</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<page string="Sales" position="after">
<!--<page string="Product Slider">
<field name="images" nolabel="1"/>
</page> -->
<!-- a copy of website_multi_image/product_images.xml-->
<page string="Product Images">
<field name="images" mode="kanban" context="{'default_name': name}">
<kanban>
<field name="name"/>
<field name="description"/>
<field name="image_alt"/>
<field name="image"/>
<templates>
<t t-name="kanban-box">
<div style="position: relative">
<div class="oe_module_vignette">
<a type="open">
<img t-att-src="kanban_image('res.partner', 'image', record.id.value, {'preview_image': 'image_small'})" class="oe_avatar oe_kanban_avatar_smallbox"/>
</a>
<div class="oe_module_desc">
<div class="oe_kanban_box_content oe_kanban_color_bglight oe_kanban_color_border">
<table class="oe_kanban_table">
<tr>
<td class="oe_kanban_title1" align="left" valign="middle">
<h4><a type="open"><field name="name"/></a></h4>
<i><div t-if="record.description.raw_value">
<field name="description"/></div></i>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</t>
</templates>
</kanban>
</field>
<!-- a copy of website_multi_image/website_product_image_carousel.xml to display the slider-->
<div class="container-fluid">
<style>
.slider-for {
min-height:50px;
background-color:grey;
}
.slider-nav {
min-height:20px;
}
</style>
<div class="row-fluid">
<p class="oe_grey">
<strong>Note:</strong> display the slideshow here now.
</p>
<div class="slider slider-for">
<t t-foreach="product.images" t-as="i">
<h2 t-esc="i.name"/>
<div><span t-field="i.image" class="img-responsive" t-field-options="{"widget": "image", "class": "img-responsive"}"/></div>
</t>
</div>
</div>
<div class="row-fluid">
<div class="slider slider-nav">
<t t-foreach="product.images" t-as="i">
<h2 t-esc="i.name"/>
<div><span t-field="i.image" class="img-responsive" t-field-options="{"widget": "image", "class": "img-responsive"}"/></div>
</t>
</div>
</div>
</div>
</page>
</page>
</field>
</record>

I realised the qweb tags is not being processed


Hi Luke, thats the project I am using. I have edited the question to include my xml file in full. I realised the qweb tags in the view are not being processed.

Cyrus Waithaka
on 4/20/15, 1:22 AM

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: 4/19/15, 5:21 PM
Seen: 1643 times
Last updated: 4/20/15, 1:22 AM