- Template variable syntax and delimiter formats
- Conditional blocks for threshold-based display
- Format specifiers for decimal places and unit suffixes
- Multi-language template output configuration
- Debugging missing or literal variable text in output
Templates are where raw station data becomes a readable web page. GraphWeather’s template engine replaces variable placeholders with live data at each publish cycle, generating static HTML that gets uploaded via FTP. Understanding the variable system, conditional logic, and format specifiers is essential for building custom station pages that display the information you care about. This guide covers the template system in depth, building on the foundational patterns in Publishing Fundamentals.
Variable Syntax
Template variables use delimiter-wrapped names that the engine recognises and replaces. Depending on the GraphWeather version, the syntax may use angle-bracket-percent or double-curly-brace notation:
<!-- Angle-bracket style -->
<span>Temperature: <%outdoor_temp%> °C</span>
<!-- Curly-brace style -->
<span>Temperature: {{outdoor_temp}} °C</span>Both styles work the same way. The engine scans the template file, finds delimited tokens, looks up the current value, and writes the result. If a variable name is not recognised, the behaviour depends on configuration: some setups leave the token as-is (useful for debugging), while others replace it with an empty string or a placeholder like “N/A”.
Core Variables
| Variable | Description | Typical Unit |
|---|---|---|
outdoor_temp | Current outdoor temperature | °C or °F |
outdoor_humidity | Relative humidity | % |
indoor_temp | Indoor temperature (console sensor) | °C or °F |
barometer | Sea-level-corrected barometric pressure | hPa or inHg |
wind_speed | Current wind speed | km/h, mph, m/s, knots |
wind_gust | Highest gust in current period | Same as wind_speed |
wind_direction | Wind direction in degrees | 0–360° |
wind_dir_text | Cardinal direction text | N, NNE, NE… |
rain_today | Rainfall since midnight | mm or in |
rain_rate | Current rainfall rate | mm/h or in/h |
dewpoint | Calculated dew point | °C or °F |
windchill | Wind chill factor | °C or °F |
heat_index | Heat index | °C or °F |
last_update | Timestamp of latest reading | Configurable format |
sunrise / sunset | Today’s sunrise/sunset times | HH:MM |
Conditional Blocks
Templates support conditional logic for threshold-based display. For example, showing a frost warning when temperature drops below zero:
<%if outdoor_temp < 0%>
<div class="alert">⚠️ Frost warning: <%outdoor_temp%> °C</div>
<%endif%>Conditions can use comparison operators (<, >, ==, !=) and combine with AND / OR logic. Nested conditions are supported but should be used sparingly — deeply nested templates become difficult to maintain.
Format Specifiers
Control decimal places and formatting with specifiers appended to variable names:
<%outdoor_temp:.1f%>— one decimal place (e.g., 22.5)<%barometer:.0f%>— no decimal places (e.g., 1013)<%wind_speed:.2f%>— two decimal places (e.g., 12.45)<%last_update:datetime%>— formatted date/time string
Multi-Language Output
For stations serving audiences in multiple languages, GraphWeather supports generating multiple output files from separate templates. Configure each template with language-specific labels and upload them to separate directories or filenames:
/weather/index_en.html ← English template
/weather/index_fr.html ← French templateVariable values (numbers, dates) can be formatted according to locale settings. Text labels are part of the template HTML, so each language file contains its own labels.
Troubleshooting Matrix
| Symptom | Likely Cause | Fix |
|---|---|---|
| Variable shows as literal text | Wrong delimiter or typo in variable name | Check delimiter style matches your version; verify variable name spelling |
| Variable shows blank/empty | Data source disconnected or variable not populated | Check station connection; verify the variable is supported by your station type |
| Encoding issues (garbled characters) | Template file saved in wrong encoding | Save template as UTF-8; add <meta charset="utf-8"> to HTML head |
| Conditional block always shows | Comparison logic error or variable type mismatch | Verify the comparison operator and that the variable returns a number, not a string |
| Old data displaying despite new readings | Browser caching or CDN cache | See Image Refresh and Caching |
FAQ
Can I use JavaScript in templates?
How do I embed graphs in templates?
<img> tags. Add a cache-busting query parameter using the last_update or publish_timestamp variable to prevent stale images.