Skip to main content

How to format smart element data?

Trim text, fix links, and show prices in your format with Expression and Format in Smart Elements.

Written by Marina Krivenets

A smart element connected to a website page (see What are Smart Elements and how to use them);

Purpose

Expression and Format change a value that Stripo pulls from a website before it goes into your email. Trim long titles, fix links, add text around a value, or show a price in the format you need.

When to use

Use Expression and Format when:

  • the price on the site looks different from the one you need in the email;

  • a link from the site has no protocol or uses a relative path;

  • a title or description is too long for the card.

They work only for data pulled from a website page. Values from a Data Source (Google Sheets, RSS, JSON) stay as they are, so prepare them in the source itself.

Here's what you'll end up with: a price that comes from the site as $1,699 and shows in your email as $1,699.00.

Where to find Expression and Format

  1. Select the smart element and open the Data tab.

  2. Click the Direction Rule icon (target) next to the field you want to change. The rule panel opens.

  3. Fill in Selector and, if needed, Attribute to get the value from the site.
    ​

  4. Click + Expression or + Format. To start from a ready-made pattern, click the arrow next to + Format and choose one.

  5. Click Check Rule and Save.

You'll know it worked when the field in the card shows the changed value.

To remove an Expression or a Format, click the trash icon next to its name.

(!) Add Expression before Format (!)

Format works only with a plain number: digits and one decimal point, with no currency signs, commas, or spaces. If the site shows $1,699, Format can't read it and the value stays the same. Add an Expression that keeps only digits and the decimal point first, then add Format.

Change a value with Expression

An Expression has two fields:

  • Expression: a regular expression that finds part of the value;

  • Replace: what goes in its place. Leave it empty to delete the match.

The ready-made patterns under the arrow cover the most common tasks:

Ready-made pattern

Expression

Replace

Before

After

Change the symbol to another one

\$

USD

$202.97

USD202.97

Trim text to a certain number of characters

(.{0,125})(.{0,})

$1

A long title

The first 125 characters

The link needs a protocol addition

^//

https://

//site.com/img.png

https://site.com/img.png

The link path needs to be changed

/image/

https://example.com/image/

/image/bag.png

https://example.com/image/bag.png

Insert content inside the got content

^(.*)$

Now $1 only

202.97

Now 202.97 only

Other useful Expressions:

Task

Expression

Replace

Before

After

Remove the currency sign

^\$

(empty)

$202.97

202.97

Keep only the number (Global on)

[^0-9.]

(empty)

$1,699

1699

In the trim pattern, replace 125 with the number of characters to keep. It counts every character: letters, digits, spaces, and symbols. The text may break in the middle of a word.

Global

Each Expression has a Global checkbox. It's off by default.

  • On: Stripo replaces every match in the value.

  • Off: Stripo replaces only the first match.

For example, the value $$$$ with Expression \$ and Replace usd gives usdusdusdusd with Global on and usd$$$ with Global off.

Tip

Test your Expression on regex101 with the exact value from the site before you paste it into Stripo. To learn the syntax, see the JavaScript RegExp reference on W3Schools.

Format a number with Format

Format applies a number pattern to the value. Separator sets the grouping separator. If you leave it empty, Stripo uses a dot.

Character

What it does

0

Shows a digit, or 0 if there's none

#

Shows a digit, or nothing if there's none

.

Marks the decimal separator

,

Marks where to group digits (the symbol comes from Separator)

'text'

Adds text as is, for example '$' or '#'

Examples for the value 202.97:

Format

Separator

Result

What happens

#######.###

(empty)

202.97

# drops missing digits

0000.000

(empty)

0202.970

0 adds missing digits

#.#

(empty)

203

Rounds to the pattern's decimals

#

(empty)

203

Rounds to a whole number

0000,000.##

(empty)

0.000.202.97

Groups digits with a dot

0000,00

-

00-02-03

Groups by two with a dash

The # number

(empty)

The 203 number

Adds text around the number

The '#' #th

(empty)

The # 203th

Quotes print # as text

Example: format a price from a website

The product page shows $1,699. You need $1,699.00 in the email.

  1. Open the rule panel for the price field and paste the price selector into Selector.

  2. Click + Expression. Set Expression to [^0-9.], leave Replace empty, and select Global. The value becomes 1699.

  3. Click + Format. Set Format to '$'#,##0.00 and Separator to ,.

  4. Click Check Rule and Save.

You'll know it worked when the price in the card shows $1,699.00.

Important to note: if the site uses a comma for decimals (for example, 1.699,99 €), [^0-9.] breaks the number. [CHECK: supported pattern for a decimal comma]

Nice, your prices now match the format of your brand. Next: fill cards from a list you already keep with a Data Source.


Thank you for taking the time to read our articles. We hope you will find this information helpful.

If you have any additional questions, please email us at support@stripo.email.

We would be glad to talk with you.


Did this answer your question?