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

I am trying to output ltr/rtl variable lang_direction in qweb tamplate like this:

            <xpath expr="//html" position="attributes">
                <attribute name="dir"><t t-esc="lang_direction"/></attribute>
            </xpath>            

This is not working. Is there a way to do it?

 

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

I used t-att-$name instead of t-attf

So it should be


<xpath expr="//html" position="attributes">

        <attribute t-if="lang_direction == 'ltr'" name="t-attf-dir">ltr</attribute>

        <attribute t-if="lang_direction == 'rtl'" name="t-attf-dir">rtl</attribute>

</xpath>

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

Hello Akram,

What about a workaround like the following:

<xpath expr="//html" position="attributes">
        <attribute t-if="lang_direction == 'ltr'" name="dir">ltr</attribute>
        <attribute t-if="lang_direction == 'rtl'" name="dir">rtl</attribute>
</xpath>   

Ảnh đại diện
Huỷ bỏ

Can we only set an attribute with xpath? Can we set it directly?