Building an nFocus site from a template
An nFocus site's pages come from a template that nFocus owns. The public portal has the template's code (its pages, layout and components); the API has the template's schema and each site's content for it. This guide covers what the public portal reads to render a site, and what the organization site edits.
Templates and versions
A template has a stable key (community-hub, youth-center) and numbered versions.
- A version's schema never changes once sites can use it. A change of fields or sections is a new version,
released together with the front-end code that renders it. Render by
templateKeyandtemplateVersion. - States:
draft(nFocus is still working on it; no site can choose it),available, andretired(no new choices or upgrades; sites already on it keep working). - The first two templates:
community-hub: an organization with several locations and many services. Pages: Home, Locations, Services, About, Give, Contact, and a page per location in one of two layouts (service-siteoryouth-center).youth-center: one youth center on one long home page: mission hero, statement band, approach, values, outcome areas, a typical week, programs by age, community impact, impact numbers, sponsorships and a closing band.
- Version 2 of both adds optional
videosandcontactssections (the community hub: videos on Home and About, contacts on Contact; the youth center: both on its home page), hidden in the sample. It is adraftuntil the front end renders the new sections; nFocus then makes it available, and a site moves to it by preview and publish. Sites on version 1 don't change.
The schema
GET /v1/manage/sites/{siteId}/website returns the draft's schema; GET /v1/manage/sites/{siteId}/templates lists
the templates a site can use, with each version's pages and sections, and the template's thumbnail (thumbnailUrl and
thumbnailAltText) once nFocus uploaded one. nFocus adds templates and versions, and previews a version's sample
content, in the admin app (see nFocus admin, "Templates").
The templates an nFocus site can use
GET https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/templates → 200 OK, JSON
curl
curl -s 'https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/templates' \
-H 'Authorization: Bearer your_keycloak_access_token'JavaScript
const response = await fetch('https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/templates', {
headers: {
'Authorization': 'Bearer your_keycloak_access_token',
},
});
const data = await response.json();C#
using var http = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/templates");
request.Headers.Authorization = new("Bearer", "your_keycloak_access_token");
using var response = await http.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();- Pages:
key,title,path(/,/locations,/locations/{slug}),layout(for item pages that share a path) andnav(in the menu). The page with nopathis shared: its sections (header,footer) show on every page. - Sections:
key,type,label, andoptional(the organization may hide it; it can't reorder sections). - Fields:
name,type,label,help,requiredand the limits for the type. - Colour slots: each has a default and the contrast checks it must pass (below).
- Heading fonts: up to six; the first is the default.
Field types
| Type | Value | Limits |
|---|---|---|
text |
One line of plain text | max characters |
paragraphs |
Plain text; paragraphs separated by a blank line (\n\n) |
max characters |
url |
https://…, or a path on the site starting with / (/#outcomes) |
500 characters |
email, phone |
Plain text | |
image |
A media id from the site's library (alt text is required there) | aspect (w:h), tolerance, minWidth |
boolean |
true or false |
|
choice |
One of the field's options values |
|
number |
A whole number | min, max |
list |
An array of objects with the list's fields |
minItems, maxItems |
ref |
{ "kind": …, "id": "…" }: a location, staff, post, service, organization content, sponsorship, video, contact, catalog activity or program |
kinds |
cta |
A button: { "kind", "label", "url" (link), "target" (register) } |
kinds |
No field holds HTML: text is shown as text. A button's kind is one of register (the catalog, or one activity or
program as its target), donate (the donation flow), call, email, directions (the organization's own phone,
email and address) and link (its url, with its own label).
Section types
The section type says which component renders it. Its fields are the words and settings the organization writes for it (headings, introductions, buttons). Sections that show the organization's items read them from the website's public endpoints, as the organization keeps them:
| Section type | Shows |
|---|---|
header, footer |
The logo (branding), the organization's name, address, phone and social links (GET P/site), and the fields' buttons |
hero, textBlock, ctaBand |
Their own fields. On a location page, the hero is the location (GET P/locations/{slug}), and a ctaBand its buttons |
locationCards, locationDirectory, map |
The locations (GET P/locations), with the services each offers (GET P/services, for the directory's filter) |
posts, announcements |
GET P/posts, GET P/announcements |
serviceGrid, programCards |
Service categories and services (GET P/services); on a location page, the location's services |
weeklySchedule |
GET P/schedules (the site's own, or ?location= on a location page) |
outcomes, impactNumbers, values, pathways, quote, sponsorships |
GET P/content (the site's own, or ?location= on a location page) |
videos |
The videos its videos list names (up to six), or, left empty, the site's published videos (GET P/videos) |
contacts |
The contacts its contacts list names (up to twelve), or, left empty, the site's public contacts (GET P/contacts) |
A section whose items come from a capability the organization turned off is left out of GET P/website, and a
reference to an item of one resolves to nothing.
The published website
GET P/website is public (a site key is optional) and answers for an nFocus site that has published its website.
An nFocus site's published website
GET https://api.nfocus.solutions/v1/portals/riverbend/central/website → 200 OK, JSON
curl
curl -s 'https://api.nfocus.solutions/v1/portals/riverbend/central/website'JavaScript
const response = await fetch('https://api.nfocus.solutions/v1/portals/riverbend/central/website');
const data = await response.json();C#
using var http = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.nfocus.solutions/v1/portals/riverbend/central/website");
using var response = await http.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();pages: every page, with its visible sections in the template's order. A hidden section isn't sent.fields: each section's fields by name. Images come as{ id, url, altText, width, height }; references and a register button'stargetas{ kind, id, name, … }. A reference to something no longer published is left out, and a register button without its target opens the catalog.branding:logo,colors(every slot, the site's choice or the template's default) andheadingFont. The registration flow on an nFocus site uses the same theme.jsonLd: the organization (schema.orgNGO) and theWebSite, built from the same data. Insert it unchanged in a<script type="application/ld+json">element, but escape<as\u003cwhen you write it there. It holds text staff typed, and a</script>in a description would otherwise end the element.primaryUrl: the site's primary address (its primary domain, else its portal path), for canonical links.- Not an nFocus site, or nothing published yet:
404 website-not-found.
Caching
The answer carries Cache-Control: public, max-age=60, stale-while-revalidate=300 and a strong ETag. Send the ETag
back in If-None-Match and an unchanged website answers 304 Not Modified with no body. A publish shows within about a
minute.
Previews
The organization site makes a preview link (POST …/website/preview-link), which points at
GET P/website?preview={token} and works for one hour on that site only. A preview answers the draft, with
"preview": true, Cache-Control: no-store and X-Robots-Tag: noindex, nofollow: render it the same way and never
cache it. A wrong or expired token serves the published website.
Editing a website
The organization site edits a site's website in two stages, a draft and the published version (see Organization site, "An nFocus site's website"):
The website draft, its schema and what blocks publishing
GET https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/website → 200 OK, JSON
curl
curl -s 'https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/website' \
-H 'Authorization: Bearer your_keycloak_access_token'JavaScript
const response = await fetch('https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/website', {
headers: {
'Authorization': 'Bearer your_keycloak_access_token',
},
});
const data = await response.json();C#
using var http = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/website");
request.Headers.Authorization = new("Bearer", "your_keycloak_access_token");
using var response = await http.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();- Content is stored by page key, section key and field name:
{ "home": { "hero": { "fields": { "headline": "…" } }, "band": { "hidden": true } } }. - Saving (
PUT …/website/draft, with the draft's ETag inIf-Match) checks types, limits and colour contrast. A draft may be incomplete. problemslists what stops the draft being published now: required fields, lists below their minimum, references to something unpublished, a template version that can't be chosen any more.- Switching template keeps every piece of content.
notShownlists what the new template has no place for; switching back shows it again.
Saving a draft someone else changed
PUT https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/website/draft → 412, problem details
curl
curl -s -X PUT 'https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/website/draft' \
-H 'Authorization: Bearer your_keycloak_access_token' \
-H 'If-Match: "stale"' \
-H 'Content-Type: application/json' \
-d '{"branding": {"colors": {"primary": "#c62828"}}}'JavaScript
const response = await fetch('https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/website/draft', {
method: 'PUT',
headers: {
'Authorization': 'Bearer your_keycloak_access_token',
'If-Match': '"stale"',
'Content-Type': 'application/json',
},
body: JSON.stringify({"branding": {"colors": {"primary": "#c62828"}}}),
});
const data = await response.json();C#
using var http = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Put, "https://api.nfocus.solutions/v1/manage/sites/3f6b1c2e-8a4d-4e7b-9f10-5c2d7e8a9b01/website/draft");
request.Headers.Authorization = new("Bearer", "your_keycloak_access_token");
request.Headers.Add("If-Match", ""stale"");
request.Content = new StringContent("""
{"branding": {"colors": {"primary": "#c62828"}}}
""", System.Text.Encoding.UTF8, "application/json");
using var response = await http.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();Colours and contrast
Each colour slot names the pairs it is used in: against a fixed colour (#ffffff) or another slot, at level text
(4.5:1) or large (3:1, large text and controls), WCAG 2.2's ratios. A colour that fails is refused when it is saved,
with an error that names the pair and the ratio it reached:
{
"code": "invalid-request",
"errors": { "branding.colors.primary": ["White text on primary buttons: the contrast is 2.38:1; it needs at least 4.5:1."] }
}
When a site changes a colour that another slot is checked against (a light band behind text), the error names the colour the site changed.