Skip to content

Utility Functions

:repeat(text, times)

Repeats the text a specified number of times.

:repeat(*, 5)   # Result: "*****"
:repeat(AB, 3)  # Result: "AB\nAB\nAB"

:hostname(value, separator, uppercase)

Formats a text as a hostname, replacing non-word characters with a separator.

Parameters: - value: Text to format - separator: Separator character (default: "-") - uppercase: Convert to uppercase ("true" or "false", default is "true")

:hostname(Web Server #1)              # Result: "WEB-SERVER-1"
:hostname(Web Server #1, _, false)  # Result: "web_server_1"

:rand(start, end, leading)

Generates a random number between start and end.

Parameters: - start: Minimum value - end: Maximum value - leading: Add leading zero for numbers < 10 ("true" or "false", default is "true")

:rand(1, 100)          # Result: A number between "01" and "100"
:rand(1, 10, false)  # Result: A number between "1" and "10" without leading zero

:include(file_path)

Includes and processes content from another ILLEX file, allowing for modular and reusable templates.

Parameters: - file_path: Path to the file to be included (with or without .illex extension)

The function reads, processes, and returns the content of the specified file, executing all ILLEX operations contained within it.

:include(header)              # Includes and processes header.illex
:include(templates/footer)   # Includes and processes a file with specific path

Use cases:

  • Modular templates: Split large documents into reusable components
  • Configuration libraries: Centralize common variables in separate files
  • Code organization: Keep related sections in dedicated files

Practical example:

@config = :include(config)    # Loads configuration variables

<html>
<head>
  <title>@config[site_name]</title>
  :include(styles)            # Includes common styles
</head>
<body>
  :include(header)            # Includes standard header

  <main>
    <h1>@config[page_title]</h1>
    <p>Content specific to this page...</p>
  </main>

  :include(footer)            # Includes standard footer
</body>
</html>