-1

I am working on an integration with Odoo, that makes use of a JavaScript applet on the website to read the attributes of an HTML element and use them to identify the logged in customer.

Unfortunately, I am a noob at front-end development and cannot get it to work.

An element like this does output the email address, for instance me@example.com, of the user onto the web page: <div t-raw="request and request.env.user.partner_id.email"/>

How can I assign the value of request.env.user.partner_id.email to the data-email attribute, instead of the hard-coded email address, kin the identification element here below??

<div
    id="customer-identification-html-element"
    data-authenticated="true"
    data-email="me@example.com"
>
</div>

I tried setting data-email="request.env.user.partner_id.email", but then the string is sent as is to the third party, without resolving its value.

I also tried t-att-data-email="request.env.user.paretner_id.email", to get an error while rendering the template.

Andrea
  • 1
  • 2
  • try with `t-attf-data-email` (note that there is f after att) also you can `t-set='foo'` to set it to a variable and call that variable in `t-attf...` – kingofsevens Apr 01 '23 at 11:50
  • Thanks @kingofsevens, That's how I solved it. I wrote the attributes as: ``` id="customer-identification-html-element" data-authenticated="true" t-attf-data-email="{{request and request.env.user.partner_id.email}}" ``` Using the curly braces and prefixing `t-attf-` was the solution. What's inside the double curly braces is then processed as code and resolves to the email address of the logged in customer, and `t-attf-` is stripped while rendering, so the external service sees it as data-email="me@example.com" Thank you also for mentioning `t-set`, really useful! – Andrea Apr 02 '23 at 18:03

1 Answers1

0

Thanks kingofsevens,

Prefixing t-attf- and using the curly braces was the solution. I wrote the <div> element as:

<div
    id="customer-identification-html-element"
    data-authenticated="true"
    t-attf-data-email="{{request and request.env.user.partner_id.email}}"
>
</div>

What's inside the double curly braces is then processed as code and resolves to the email address of the logged in customer, and t-attf- is stripped while rendering, so the external service sees it as data-email="me@example.com"

Thank you also for mentioning t-set, really useful!

PS: thanks @rob for mentioning the invalid HTML, corrected it!

Andrea
  • 1
  • 2