Odoo stores a contact’s first and last name in a single field. Sometimes you want to greet someone by first name only in an email template. A short expression in your QWeb reports handles it.
The expression
Split the name field on spaces and take the first part:
Variable: ${object.partner_id.name.split()[0]}
QWeb email template: <t t-out="object.partner_id.name.split()[0]"></t>
split() breaks the full name into separate words; [0] takes the first word, which is the first name.
Example: salutation in a quotation email
The QWeb block below puts “Hi [first name],” above the body of a sales order email:
<div style="margin: 0px; padding: 0px;">
<p style="box-sizing:border-box;margin: 0px; padding: 0px; font-size: 13px;">
<t t-set="doc_name" t-value="'quotation' if object.state in ('draft', 'sent') else 'order'"></t>
Hi <t t-out="object.partner_id.name.split()[0]"></t>,
<br><br>
As agreed, here is the link to our quotation.
<br>You can view it online through the link in this email. The PDF version you can download there sets out the assumptions, the project scope and the conditions in more detail.
<br><br>If everything looks good, you can confirm the quotation online.
<br><br>
Let me know if you have any questions.
<t t-if="not is_html_empty(object.user_id.signature)" data-oe-t-group-active="true">
<br><br>
<t t-out="object.user_id.signature or ''" data-oe-t-inline="true">--<br>Team Radical Fanatics</t>
</t>
<br><br>
</p>
</div>
Watch out
- If a first name has multiple words (for example “Jan Willem”), you only get the first word. For most salutations that is fine.
- If a contact has no name, the expression can throw an error. In critical templates, guard against it with a fallback.
Ref: Odoo forum: dynamic placeholder for only first name
Need a hand with your Odoo setup?
Stuck on email templates or other configuration? Book an Odoo scan or get in touch