Introduction
Our ZPL Label Designer can handle custom text blocks with multiline text out-of-the-box. However, what if you want to use a field from your Odoo models and include its content in your newly created labels? The good news is that it’s possible to achieve, though it will require some technical steps on your part.
This article will guide you through the necessary steps to configure multiline fields for ZPL labels.
Example Scenario
Let’s assume you want to use the “Purchase Description” field from the Product Template model. This field supports multiple lines of text input:
For simplicity, we will create a very basic label containing two fields:
Product Name
Purchase Description
When you preview such a label, you’ll notice that the line breaks are missing:
The issue arises because the Designer doesn’t know the exact text content at design time, as the field values are dynamic. To resolve this, you need to directly modify the label’s content in Odoo.
Steps to Add Multiline Fields
Step 1: Publish the Label in Odoo
Create and save your label in the Designer.
Publish the label in Odoo.
Navigate to the label’s view editor. You can do this by clicking the Open Label View button (this button is visible only in debug mode):
Note: Any changes made directly to the label view in Odoo will be overridden if you publish updates from the Designer. After each update, repeat the modifications described in this guide to ensure multiline fields render correctly.
Step 2: Identify the Multiline Field
Find the field where multiline text is required. In our example, this will be the “Purchase Description” field:
Step 3: Modify the Label Content
Depending on the text alignment, apply one of the following changes to the field’s code:
For Left or Right-Aligned Text
Use the following code:
<t t-esc="doc.description_purchase.replace('\n', '`0A')"/>
For Center-Aligned Text
Use this code:
<t t-esc="doc.description_purchase.replace('\n', '\\&')"/>
Step 4: Save and Test
Save the updated label view.
Print the label to confirm that the text now splits into multiple lines as expected.
Need Further Assistance?
If you encounter any issues or need help splitting text into multiple lines, please contact our support team: https://support.ventor.tech/