Displaying JSON values¶
This guide explains how to display scheduled item data inside your HTML template. Recall that the base template uses a fixed <div id="your-content" class="your-content"></div> as the main content area, while the <body> keeps a black background (the sign player supplies black as a default, and the base template sets it explicitly).
Every scheduled item reaches the sign as a JSON object — the fields the source or the Excel import provided plus the ones Onlit adds (see Template data fields). The examples below use this item:
{
"room": "Test Room",
"title": "Test Scheduled Item 1",
"program": "Main Event",
"speakers": [
{ "first_name": "John", "last_name": "Doe", "role": "Speaker" },
{ "first_name": "Samantha", "last_name": "Fisher", "role": "Sponsor" }
],
"sponsors": {
"sponsor": [
{ "company": { "name": "Zaibatsu Corp." } },
{ "company": { "name": "Company XYZ" } }
]
},
"time_start": "2025-03-18 18:00:00",
"time_end": "2025-03-18 21:30:00"
}
To see the real fields of one of your items, open its JSON page in the app (Editing scheduled item JSON).
Plain values¶
Put the field name in the data-field attribute of the element that should show it. Any
text already inside the element is a placeholder until the data arrives, so leave it empty:
<div id="your-content" class="your-content">
<h1 class="title-text" data-field="title"></h1>
<p class="room-text" data-field="room"></p>
<p data-field="start_time_ampm end_time_ampm"></p>
</div>
The <h1> shows Test Scheduled Item 1, the first <p> Test Room, and the second
6:00 PM 9:30 PM — a space-separated list of fields joins their values. Classes and other
attributes on the element are untouched.
room is system-managed
The system fills room from the assigned room's current Room Display Title (when set),
otherwise its title, so renaming a room updates every sign without rewriting item JSON.
data-field="room" is still exactly how you display it — only where the value comes
from is special. See Room is system-managed.
Download the plain-values example.
Objects and arrays¶
Nested values are addressed with a path: data-field="sponsors.sponsor[0].company.name"
shows the first sponsor. To show every element of an array, point data-field at the
array and name a <template> with data-template-id; the template's content is cloned
once per element, and bindings inside it read that element's fields:
<div class="sponsor-container">
<span class="sponsor-leading-text">Sponsored by: </span>
<span data-field="sponsors.sponsor" data-template-id="sponsor-item-template"></span>
<template id="sponsor-item-template">
<span class="sponsor-text" data-field="company.name"></span>
</template>
</div>
This renders the two company names one after the other. Separate them in CSS rather than in the data:
A <ul> or <ol> container with an <li> in the template gives a list instead. Templates
can nest — a row template can itself contain a data-field + data-template-id pair for a
list inside each element, and may hold its own helper <template>, which is looked up
before the document-level ones (see the Data binding reference).
Conditional rendering¶
Sometimes you only want to show certain parts of your template when the JSON data meets specific criteria. For example, you may wish to display only speakers whose role is "Speaker" and hide others. To do this, use the data-condition attribute on the element you want to control.
The attribute holds a JavaScript expression evaluated against the current item (or, inside a list template, the current element). A false result hides the element; a true one shows it.
<div class="speakers-container">
<span data-field="speakers" data-template-id="speaker-item-template"></span>
<template id="speaker-item-template">
<span class="speaker-text"
data-condition="role === 'Speaker'"
data-field="first_name last_name"></span>
</template>
</div>
For each speaker the player clones the template, checks role === 'Speaker', and keeps
the span only when it is true — so John Doe appears and Samantha Fisher does not.
role !== 'Sponsor' would do the opposite; && and || combine conditions, and a bare
field name (data-condition="program") hides the element when that field is missing or
empty, unless the browser or the page already has that name
(Data binding reference). Conditions
work on top-level elements too, for example to show a notice only during gaps:
Download the conditional example.
Related¶
- Data binding reference — syntax, missing fields, failed conditions
- Binding attributes with data-attribute — values into
src,href,class, CSS hooks - Template data fields — the fields Onlit adds to every item
- Time formatting — dates and times in your own format