Intro to formulas

To manipulate data in your frontend, you can use WeWeb formulas.

Common examples include but are not limited to:

Binding formulas

You can use WeWeb formulas in any binding:

Local formula

In the example above, you can see:

  1. we opened the binding explorer,
  2. went to the formula tab to look for the pre-built switch formula, and
  3. wrote a formula directly in the explorer to format the text on the page based on the value of item in our collection.

This formula is local in the sense that, if we wanted to use it elsewhere in our app, we would have to re-write or copy/paste it.

Create a global formula

As your app grows in complexity, we recommend you build global formulas in the Actions tab that you can then use throughout your app:

Global formula

In the example above, you can see:

  1. in the Actions tab,
  2. we created several global formulas,
  3. the formatNumber_nocode formula takes a Text input that expects a number
  4. in the binding explorer, global formulas can be found in the From project section of the formula tab

Bind to a global formula

Global formulas are helpful because you can use them everywhere:

Global formula in action

In the example below, you can see:

  1. we opened the binding explorer to a text element,
  2. went to the formula tab,
  3. used our global formatNumber_nocode formula, and
  4. built on top of it to format additional text.

Global vs local formulas

In some cases, it makes sense to create formulas that are scoped to a specific element or component.

In other cases, it's helpful to create global formulas that you can reuse throughout your app.

As a general rule, if you catch yourself re-writing or copy/pasting formulas multiple times, it's a sign you might want to create a global formula instead because, if you need to debug or improve it down the line, you can do it in one place.

In addition, using global formulas will allow you to see which ones are being used on a page:

Global formula page filter

Last Updated:
Contributors: Joyce Kettering