Maximizing code reusability with DRY LookML: Defining a string once to use throughout your LookML project Stay organized with collections Save and categorize content based on your preferences.
You can use the LookMLconstant 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: 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: This technique helps you save time by defining conditional formatting specifications to use on multiple fields.
Ingredients
- Your project'smanifest file
- The LookML
constantparameter @{constant_name}syntax to reference existing constants- The LookML
htmlparameter - Liquid variables
Prerequisites
Example: Using the same string in the labels of multiple Explores
Suppose you want to create two Explores, labeledSan Francisco Users andSan Francisco Orders in the UI, but you don't want to manually type the text for each label.

To do this, you can define a constantplace_name with the value"San Francisco" in theproject manifest file 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 theusers andorders Explores, specifying"@{place_name} Users" and"@{place_name} Orders" as values for thelabel parameter, as in the following example:
explore: users { label: "@{place_name} Users"}explore: orders { label: "@{place_name} Orders"}In this example, Looker displaysSan Francisco Users andSan Francisco Orders in the Explore menu and in the titles of the Explores, rather than the defaultUsers andOrders labels.
Suppose you want to update all the references toSan Francisco toBay Area.

Rather than having to update each reference manually, you only have to make a single update to theplace_name constant in the manifest file for your project:
constant: place_name { value: "Bay Area"}Since you defined theplace_name constant, you don't have to manually changeSan Francisco toBay Area in multiple places. The references toSan Francisco with theplace_name constant will be replaced withBay Area, so Looker will displayBay Area Users andBay 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.

By setting this formatting as the value for a LookML constant, you can specify the formatting just once by usingLiquid variables andHTML. Then, you can reference the constant whenever you want to apply that formatting to a field.
For example, you can create a constant callednegative_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 constantnegative_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 thehtml parameter.
For example, you can createTotal Amount measure oftype: sum and specify@{negative_format} as the value for thehtml parameter:
measure: total_amount { type: sum value_format_name: usd sql: ${amount} ;; html: @{negative_format} ;;}In your table, negative values for theTotal Amount measure will be formatted as specified in thenegative_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 thenegative_format constant in thehtml parameter for those fields.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-18 UTC.