Text variables: dynamic content

Use text variables to make the content of your modules dynamic – for example to personally welcome a user to your intranet. They help you automatically updating wordings and phrases used in many places on your site and allow you to smoothly run a site in different languages.

You can use text variables in most places in Refined where you can add text: layouts, categories, modules, announcement banners, and more. Refined features default text variables, as well as the option to create your own custom text variables (available in Refined for Jira Service Management version 3.2 and up).

In this example we used $userfirstname in the primary text of a Navigation Highlight module.

Default text variables

These out-of-the-box text variables are available by default.

Variable

Description

Introduced in version

Variable

Description

Introduced in version

$username

The logged-in user’s username.

 

$userfullname

The logged-in user’s full name.

 

$userfirstname

The logged-in user’s first name.
Note: this does not work for names formatted as "lastname, firstname."

2.0

$sitename

The site’s name.

2.0

$siteid

The site’s ID.

2.0

$categoryname

The category’s name.

2.0

$categoryid

The category’s ID.

2.0

$serviceprojectdesc

The service project’s description.

3.5

$serviceprojectid

The service project’s ID.

Note: this text variable used to be called $servicedeskid.

2.0

$serviceprojectname

The service project’s name.

Note: this text variable used to be called $serviceprojectname.

2.0

Custom text variables

A custom text is one that you set up in your system. This lets you create even more dynamic content on your website and lets to create a dictionary for the language switcher.

Create a custom text variable

  1. Go to the Refined Administration.

  2. Click the Languages tab and scroll down to the Dictionary section.

  3. Click Add text variable.

  4. Add the text variable’s name formatted as $variable$.

  5. Add the text variable’s translation as the default value. If used together with the Languages feature, you can add translations for each language. When a user’s language is not included in this list, they’ll see the default value.

When adding many different language values, copying the Default Value field can help speed up the process. It lets you easily start from the same value or even keeping it the same for this language without having to manually retype it.

Filters

It’s possible to filter on empty/translated values and text/key search. You can also further filter the results by language or tags.

Tags

For each text variable you can add Tags. This can be done when creating the text variable or added in later. Tags are meant to be a tool to help you organize or group your text variables in whatever way you see fit.

When adding a custom variable, you can see multiple fields: one for the default value, and one per language you’ve enabled in Refined.

Nest default variables within a custom text variable

It’s possible to nest one or more default variables within a custom text variable, for example:

Custom text variable

Value

Custom text variable

Value

$welcome$

Welcome to $sitename, $userfirstname!

However, it is not possible to nest custom variables within one another. This means that the following would not work:

Custom text variable

Value

Custom text variable

Value

$first$

coffee

$second$

I like $first$

Note that in the Site Builder you can only use custom text variables that don’t nest any variables at all, or that nest one or more of the following variables:

Text variable

Description

Introduced in version

Text variable

Description

Introduced in version

$username

The logged-in user’s username.

 

$userfullname

The logged-in user’s full name.

 

$userfirstname

The logged-in user’s first name.
Note: this does not work for names formatted as "lastname, firstname."

2.0

Examples of custom variables

In this example, we translate a category called Help & info. After completing these steps, the category name will automatically be translated anywhere it appears on your site.

  1. Click Add text variable and add the text variable’s name and translations.

  2. Save your entries and go to the Site Builder tab.

  3. Click the Cogwheel of the category you wish to translate.

  4. Enter your new text variable as the category’s name.

In this example, we create an announcement banner that notifies users of planned maintenance.

  1. Click Add text variable and add the text variable’s name and translations.

  2. Save your entries and go to the Announcements tab. We will build the message in two parts: the message in the text variable and the data in a general format.

In this example, we add a text to the top of the Search Highlight to inspire visitors to search for help. The entered text will be a combination of text and a text variable.

  1. Click Add text variable and add the text variable’s name and translations. In this screenshot you can see we added $sitename as a nested variable.

  2. Save your entries, go to a page on your website and add a Search Highlight module.

  3. Add your new text variable into the module’s primary text.

Scripted text variables

Custom text variables can execute small scripts, which lets you use them to display dynamic values or to add a condition to them. For example, you can create a $greeting$ text variable that says Good morning or Good afternoon depending on the time of day.

Syntax

Wrap your script in curly brackets: {script}. Everything within the brackets will be replaced by the script’s returned value. The script will be executed using a Function() constructor.

Examples

Custom text variable

Value

Custom text variable

Value

$copyrightMessage$

Copyright ACME {return (new Date()).getFullYear()}"

$greeting$

{if ((new Date).getHours() < 12) { return "Good morning" } else { return "Good afternoon" }}

Limitation

The logic syntax works in every area of Refined where you can use default text variables, except in the Site Builder.

Import or export custom text variables

It’s possible to import and export your custom text variables. When exporting, a zip file is created containing one .properties file per language. You can import a whole zip file with multiple languages or single .properties language files.

When importing a dictionary, all current keys are merged with new ones. Duplicates will be overwritten by the imported file.

You can edit and create the files in whatever tool you see fit but it’s important that they are saved using UTF-8 encoding to ensure they are read properly upon importing. When the files are exported, any non-ascii characters are escaped and written as their unicode counterpart.