> [!NOTE]
> **Note:** This page is part of the [Looker cookbook: Maximizing code reusability with DRY LookML](https://docs.cloud.google.com/looker/docs/best-practices/dry-lookml-cookbook.md.txt).

You can use the LookML `constant` parameter within your project's manifest file to define a string that can be used throughout your project. LookML constants can be useful when you need to define a specific string --- such as a number, a name, or HTML formatting for field values --- and reuse that value throughout your project.

This page includes the following examples of using LookML constants to define and maintain reusable strings values in once place:

- [Using the same string in the labels of multiple Explores](https://docs.cloud.google.com/looker/docs/best-practices/dry-cookbook-4.md.txt#example_using_the_same_string_in_the_labels_of_multiple_explores): This technique helps you save time if you reuse common strings, such as words, phrases, or location names in your definitions.
- [Applying the same formatting to negative values for multiple fields](https://docs.cloud.google.com/looker/docs/best-practices/dry-cookbook-4.md.txt#example_applying_the_same_formatting_to_negative_values_for_multiple_fields): This technique helps you save time by defining conditional formatting specifications to use on multiple fields.

## Ingredients

- Your project's [manifest file](https://docs.cloud.google.com/looker/docs/lookml-project-files.md.txt#project_manifest_files)
- The LookML [`constant`](https://docs.cloud.google.com/looker/docs/reference/param-manifest-constant.md.txt) parameter
- `@{constant_name}` syntax to reference existing constants
- The LookML [`html`](https://docs.cloud.google.com/looker/docs/reference/param-field-html.md.txt) parameter
- [Liquid variables](https://docs.cloud.google.com/looker/docs/liquid-variable-reference.md.txt)

## Prerequisites

- [A configured LookML model](https://docs.cloud.google.com/looker/docs/generating-a-model.md.txt#when_you_need_to_configure_models)
- [Permissions to develop LookML](https://docs.cloud.google.com/looker/docs/admin-panel-users-roles.md.txt#permission_sets)

## Example: Using the same string in the labels of multiple Explores

Suppose you want to create two Explores, labeled **San Francisco Users** and **San Francisco Orders** in the UI, but you don't want to manually type the text for each label.

![](https://docs.cloud.google.com/static/looker/docs/images/dry-cookbook-constant-example-1-2304.png)

To do this, you can define a constant `place_name` with the value `"San Francisco"` in the [project manifest file](https://docs.cloud.google.com/looker/docs/other-project-files#project_manifest_files) for your project:

    constant: place_name {
      value: "San Francisco"
    }

This constant can then be referenced in any part of your project where a string is accepted, using the syntax `@{place_name}`. In this example, you can define the `users` and `orders` Explores, specifying `"@{place_name} Users"` and `"@{place_name} Orders"` as values for the [`label` parameter](https://docs.cloud.google.com/looker/docs/reference/param-explore-label.md.txt), as in the following example:


    explore: users {
      label: "@{place_name} Users"
    }

    explore: orders {
      label: "@{place_name} Orders"
    }

In this example, Looker displays **San Francisco Users** and **San Francisco Orders** in the Explore menu and in the titles of the Explores, rather than the default **Users** and **Orders** labels.

Suppose you want to update all the references to **San Francisco** to **Bay Area**.

![](https://docs.cloud.google.com/static/looker/docs/images/dry-cookbook-constant-example-2-2304.png)

Rather than having to update each reference manually, you only have to make a single update to the `place_name` constant in the manifest file for your project:

    constant: place_name {
      value: "Bay Area"
    }

Since you defined the `place_name` constant, you don't have to manually change **San Francisco** to **Bay Area** in multiple places. The references to **San Francisco** with the `place_name` constant will be replaced with **Bay Area** , so Looker will display **Bay Area Users** and **Bay Area Orders** in the Explore menu and in the titles of the Explores.

## Example: Applying the same formatting to negative values for multiple fields

Imagine that you want negative data values to be displayed in red and within parentheses wherever they appear in charts or queries.

![](https://docs.cloud.google.com/static/looker/docs/images/lookml-constant-html-formatting-2100.png)

By setting this formatting as the value for a LookML constant, you can specify the formatting just once by using [Liquid variables](https://docs.cloud.google.com/looker/docs/liquid-variable-reference.md.txt) and [HTML](https://docs.cloud.google.com/looker/docs/reference/param-field-html.md.txt). Then, you can reference the constant whenever you want to apply that formatting to a field.

For example, you can create a constant called `negative_format` that you can use to apply this formatting to a field:


    constant: negative_format {
      value: "{% if value < 0 %}
                <p style='color:red;'>({{rendered_value}})</p>
              {% else %}
                {{rendered_value}}
              {% endif %}"
    }

This code creates the constant `negative_format`, which specifies that negative data values should have a red font and be surrounded by parentheses. You can then apply this formatting to dimensions and measures in your dataset by using the [`html` parameter](https://docs.cloud.google.com/looker/docs/reference/param-field-html.md.txt).

For example, you can create **Total Amount** measure of [`type: sum`](https://docs.cloud.google.com/looker/docs/reference/param-measure-types.md.txt#sum) and specify `@{negative_format}` as the value for the `html` parameter:


    measure: total_amount {
      type: sum
      value_format_name: usd
      sql: ${amount} ;;
      html: @{negative_format} ;;
    }

In your table, negative values for the **Total Amount** measure will be formatted as specified in the `negative_format` constant definition, with a red font and surrounded by parentheses.

If you want to apply the same formatting to negative values for other fields, you can reference the `negative_format` constant in the `html` parameter for those fields.