How to add multiline fields to ZPL labels?

How to add multiline fields to ZPL labels?

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:

image-20241224-123022.png

For simplicity, we will create a very basic label containing two fields:

  • Product Name

  • Purchase Description

image-20241224-123107.png

When you preview such a label, you’ll notice that the line breaks are missing:

image-20241224-123150.png

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

  1. Create and save your label in the Designer.

  2. Publish the label in Odoo.

  3. 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):

image-20241224-123334.png

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:

image-20241224-123445.png

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

  1. Save the updated label view.

  2. Print the label to confirm that the text now splits into multiple lines as expected.

image-20241224-124318.png

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/

Related Posts