[blocks]
Blocks are a powerful feature in Rhyme that allow you to organize and structure your code.
block syntax
All blocks in Rhyme are declared on a separate line and are surrounded by square brackets [
and ]
. This simple syntax makes blocks easy to spot and understand in your code.
[block-name]
// Your code goes here
[another-block]
// More code here
The square brackets clearly mark where one section ends and another begins, helping you organize your app into logical pieces.
passing variables to blocks
You can pass variables into a block by specifying them with variable references in the block declaration:
[greet-user $name]
.text "Hello $name!"
.text "Welcome to our app!"
When you call this block from elsewhere in your app, you provide the value:
[start]
$user-name = "Sarah"
goto [greet-user $user-name]
The variable reference can then be used throughout the block by its name. This makes blocks reusable and flexible - the same block can work with different data each time it’s called.
special blocks
Some blocks in a Rhyme app carry special meaning and are automatically executed by the system:
[init]
The [init]
block runs once when your app first loads. This is the perfect place to:
- Set up initial variables
- Configure app settings
- Load data that needs to be ready before users interact
- Define custom colors, fonts, or icons
[init]
// Set up app configuration
set-app-title "My Amazing App"
color #brand is #purple6
icon !logo is !mdi:rocket
$app-version = "1.0.0"
[start]
The [start]
block is the first block executed after initialization. Think of it as your app’s main entry point. This is where you:
- Display the initial user interface
- Show welcome messages
- Set up the main navigation
- Begin the user’s journey
[start]
text/title "Welcome to My App!"
text/paragraph "Let's get started..."
button/text "Begin" {
goto [main-menu]
}
If your app doesn't have a [start]
block, Rhyme will look for and execute the first block it finds in your code.
coming soon
More documentation will cover:
- Creating custom blocks
- Block naming conventions
- Navigating between blocks
- Block parameters and return values
- Advanced block patterns
Check back soon for complete documentation on blocks.