Show data on a page
A page is a route, an access rule, and a list of regions. A region reads one table and renders it in one shape. This guide covers the four regions that only read.
List rows in a table
Section titled “List rows in a table”report is the region for a screen somebody works in. It gives you search, filters, sortable
columns, pagination, and an empty state.
page members "Members" { route: /members access: board
report of members "All members" { columns: last_name, first_name, email, joined_on search: last_name, first_name, email filter: fee_group, active sort: last_name page_size: 25 empty: "No members yet." }}Every column in columns is sortable. The reader sorts by clicking a heading, and the link
works with JavaScript turned off.
Search is case-insensitive and folds letters beyond ASCII, so a search for öztürk finds Öztürk. The
engine compares the text itself rather than leaving it to the database’s byte order.
A report shows 25 rows per page unless you write page_size: with another number. The
Previous and Next links keep the search, the filters, and the sort. Write limit:
instead when the report must show one screen of rows and no pages.
Open one row from the list
Section titled “Open one row from the list”row -> names the page to open when somebody clicks a row.
report of members "All members" { columns: last_name, first_name, email row -> member}The target page carries the row in its route:
page member "Member" { route: /members/{member} new_route: new access: board
form of members { fields: first_name, last_name, email, fee_group actions: save, delete }}new_route: gives the same page a second address for creating a row. new_route: new replaces
the last parameter of the route with new, so the address is /members/new. The engine cannot
guess the word, so you write it.
For a second link per row, use row_action:
row_action "Signups" -> event_signupsOpen a row at an address under its parent
Section titled “Open a row at an address under its parent”An enrolment belongs to a course, so its address can name the course too:
/courses/3/enrolments/7. Give the target page a route with the parent first:
page enrolment "Enrolment" { route: /courses/{course}/enrolments/{enrolment} access: teacher
data enrolment of enrolments
detail of enrolments { row: :enrolment fields: student, status }}{course} is the name of the ref column that points from an enrolment to its course. The
engine checks it when it reads the enrolment, so /courses/4/enrolments/7 is a 404 when
enrolment 7 is in course 3.
Link to the page from a list of enrolments, as usual:
list of enrolments { where: course = :course.id columns: student, status row -> enrolment}The engine fills {course} from each row’s own course, and {enrolment} from its id. The list
must show rows of the table that the target page is about, here enrolments. For the rules, see
A row link fills the earlier parameters.
To create an enrolment at /courses/3/enrolments/new, add new_route: new and write the course
from the address with set course = :route.course. The engine checks the course in the address
before the form shows and when it is saved. See
A create address under a scope.
Show one record
Section titled “Show one record”detail renders one row as a record rather than as a table row. Use it for an article, a
member file, or any page that is about one row.
A detail can show a multi or a list, because a metadata line has room for a set of
links. A report cannot, because a cell holds one value.
page post "{:post.title}" { route: /news/{slug} access: public
data post of posts where status.public
detail of posts { row: :post fields: published_at, author, tags body: body }}Two things are happening here.
data post of posts binds the row that the URL names. The name post is then available to
the rest of the page.
{:post.title} interpolates the bound row into the page title. Any text an author writes can
interpolate a value this way.
Show a public list
Section titled “Show a public list”list renders the same rows as a report, in a layout for reading. It has no search box and no
filters.
Use a list for a page a visitor reads and a report for a screen a member works in. They
make different promises, which is why they are two regions and not one region with a flag.
Count rows on a dashboard
Section titled “Count rows on a dashboard”stats groups a table and renders the totals as tiles.
page dashboard "Dashboard" { route: / access: board
stats of members "Members by status" { group_by: active }
stats of posts "Posts by state" { access: editor group_by: status }}The second region carries its own access:. An editor sees both tiles. A board member without
the editor role sees only the first, and the second is absent rather than refused.
Narrow a region to some rows
Section titled “Narrow a region to some rows”where: adds a fixed condition on top of the access rule.
report of events "Coming up" { columns: name, starts_at, place where: starts_at >= now sort: starts_at}A condition can compare columns, use now and today, walk a reference, and ask whether a
related set is empty. It cannot call a function you write, because a condition has to become
SQL that the engine can reason about.
NOTE: On a page that binds a row, a region over a different table must reference that row
in its where:, such as where: event = :event.id. The compiler refuses a region that does
not, because nothing else relates the two.
List the rows that belong to one record
Section titled “List the rows that belong to one record”A page about one record often lists its related rows: the registrations of an event, the marks
of an enrolment. When the record’s table declares the relation, name it after a colon. The
table events declares registrations list(registrations.event):
page event "{:event.name}" { route: /events/{event} access: board
data event of events
report of :event.registrations "Registrations" { columns: name }}The region lists the registrations whose event is this event. It is the same region as
report of registrations { where: event = :event.id }, so it has the same search, exports and
row links. Add a where to narrow it further: report of :event.registrations where confirmed.
Regions lists which
regions accept a relation and which columns count as one.