Variables
Variables are the heart of data management in Rhyme. They store and track information throughout your app’s lifecycle, from simple text values to complex data structures.
Understanding Variables
Variables in Rhyme are containers that hold values you can use throughout your app. They follow a simple naming convention - all variables start with a dollar sign $
followed by a descriptive name using kebab-case (words separated by hyphens).
Variable Types
Rhyme supports several types of variables:
- Regular Variables - User-defined variables like
$user-name
,$count
,$is-active
- System Variables - Built-in variables in ALL CAPS like
$TODAY
,$NOW
,$VERSION
- Special Variables - Platform-provided values that give you access to system information
Quick Examples
// Setting variables
set $user-name = "Alice"
set $score = 100
set $is-logged-in = true
// Using variables in UI
.text "Welcome, $user-name!"
.text "Your score: $score"
// Conditional logic with variables
if $is-logged-in
.button "Logout"
else
.button "Login"
Variable Naming
Good variable names make your code easier to understand:
- ✅
$user-email
- Clear and descriptive - ✅
$total-items
- Uses kebab-case - ✅
$is-active
- Boolean naming convention - ❌
$userEmail
- Avoid camelCase - ❌
$x
- Too vague
Learn More
- Variable Types - Detailed guide on different variable types
- Special Variables - Built-in system variables
- Variables Action Set - Actions for managing variables
Naming Conventions
Variable names in Rhyme follow specific conventions that make your code readable and consistent.
The Basics
All variables in Rhyme start with a dollar sign $
followed by a descriptive name:
set $user-name = "Alice"
set $total-count = 42
set $is-logged-in = true
Kebab-Case Style
Rhyme uses kebab-case (words separated by hyphens) for variable names:
- ✅
$user-email
- Correct kebab-case - ✅
$first-name
- Clear and readable - ✅
$shopping-cart-total
- Multiple words connected - ❌
$userEmail
- Avoid camelCase - ❌
$user_email
- Avoid underscores
Descriptive Names
Choose names that clearly describe what the variable contains:
Special Variables
Rhyme provides a comprehensive set of special variables that are automatically available in all apps. These variables give you access to system information, app state, date/time values, and much more.
date & time variables
current date/time
$TODAY
- Current date and time$NOW
- Current date and time (same as $TODAY)$TIMESTAMP
- Current timestamp in milliseconds
formatted dates
$DATE
- Medium format date (e.g., “Jan 15, 2025”)$LONGDATE
- Long format date (e.g., “January 15, 2025”)$SHORTDATE
- Short format date (e.g., “1/15/25”)
formatted times
$TIME
- Medium format time (e.g., “2:30:45 PM”)$LONGTIME
- Long format time with timezone$SHORTTIME
- Short format time (e.g., “2:30 PM”)
date components
$DAY
- Full day name (e.g., “Monday”)$DAYSHORT
- Short day name (e.g., “Mon”)$MONTH
- Full month name (e.g., “January”)$MONTHSHORT
- Short month name (e.g., “Jan”)$MONTHNUM
- Month as number (1-12)$YEAR
- Two-digit year (e.g., “25”)$YEARNUM
- Four-digit year (e.g., 2025)
time components
$HOUR
- Two-digit hour (e.g., “14”)$HOURNUM
- Hour as number (0-23)$MINUTE
- Two-digit minute (e.g., “05”)$MINUTENUM
- Minute as number (0-59)$SECOND
- Two-digit second (e.g., “09”)$SECONDNUM
- Second as number (0-59)
time slots
$TIMESLOTS60
- Array of hourly time slots$TIMESLOTS30
- Array of half-hour time slots$TIMESLOTS15
- Array of 15-minute time slots$TIMESLOTS10
- Array of 10-minute time slots$TIMESLOTS5
- Array of 5-minute time slots
name arrays
$DAYNAMES
- Full weekday names array$DAYNAMESSHORT
- Short weekday names array$MONTHNAMES
- Full month names array$MONTHNAMESSHORT
- Short month names array
app & system information
app details
$APP
- Current app information object$APPNAME
- Name of the current app$APPGROUP
- App group identifier$AID
- App ID$APPICON
- App icon reference$APPBIN
- App binary data$APPBINLEN
- Size of app binary in bytes$VERSION
- VM version
execution context
$BLOCK
- Current block name$BLOCKID
- Current block ID$BLOCKS
- Array of all block names$BLOCKIDS
- Array of all block IDs$PC
- Program counter$STEP
- Current step count
environment
$ENVIRONMENT
- Runtime environment (“browser”, “node”, “worker”, “unknown”)$ENV
- Extended environment information$LANGUAGE
- Current language setting (e.g., “en|US”)$REGION
- Geographic region$PWA
- Whether running as Progressive Web App
user & authentication
$ACCOUNT
- Account information$PLAN
- Current subscription plan$AUTH
- Authentication headers$AUTHMODE
- Authentication mode$AUTHHEADERS
- Generated auth headers
client information
$CLIENT
- Client object$CLIENTID
- Client identifier$CLIENTPASSCODE
- Client passcode$CLIENTTOKEN
- Client authentication token$CLIENTCAN
- Client capabilities object (badge, listen, locate, speak, vibrate)
url & location
$URL
- Full current URL$HOSTNAME
- Current hostname$SUBDOMAIN
- First part of hostname$ORIGIN
- Protocol and hostname$URLPATH
- URL pathname$URLHASH
- URL hash/fragment
colors & styling
$COLORA
- Primary color value$COLORB
- Secondary color value$COLORC
- Tertiary color value$COLORS
- Array of all available colors$APPWIDTH
- Application width setting
system lists
variables & state
$VARIABLES
- Array of all defined variable names$SYSVARS
- Array of all system variable names$VARMETA
- Variable metadata keys$STATE
- Complete state object$VARBUF
- Variable buffer
ui & components
$CUSTELEMENTS
- Custom elements available$CUSTOMELEMENTS
- Registered custom elements$TEMPLATES
- Available templates$UIPOSITIONS
- UI elements with position data$LASTEL
- Last created element
resources
$IMAGES
- Array of loaded image names$ICONS
- Array of available icons$ACTIONS
- Array of all action names$PLUGINS
- Array of loaded plugins
variable metadata
These functions accept a variable name as parameter:
$variables
Variables are the foundation of data management in Rhappsody applications. They provide a simple, intuitive way to store and manipulate information throughout your app.
key concepts
naming conventions
- Variables are prefixed with a
$
symbol (e.g.,$my-var
) - All variables are global to the entire app
- Variable names are case sensitive -
$my-var
is different from$My-Var
- Convention: use lowercase letters, numbers, and dashes (e.g.,
$user-name
,$item-count
)
best practices
- Use descriptive, meaningful names that clearly indicate the data’s purpose
- Longer names are encouraged for clarity (e.g.,
$customer-email
instead of$email
) - Ensure variable names are unique across your entire application
- Remember that all variables share the same global scope
variable types
string
Text values enclosed in double quotes. Use single quotes when the value contains double quotes.