How-to library · Developer docs

How-to library

Task-shaped pages: a title that starts with a verb, the situation in a few lines, the steps, the working code in both engines, and why this way rather than another. Found from a search, done, and left.

Topic 8 how-tos

Getting things on screen

Render a list of child pages under the current page A section landing page lists its own pages from the tree, so nobody maintains the list by hand. Published children come back in position order; guard for the admin preview, where unpublished ones appear too. Build a breadcrumb trail from a record's ancestors getAllParents() returns a page's ancestors from the root down. Label the root "Home" yourself, link the rest with getFullPath(), and build a post's or record's trail from its container instead. Output a menu with the current item highlighted Read the admin's menu by its exact name, loop the root elements and their children, and mark the current item with _url.isCurrentPath() or a path prefix. Unpublished elements show to admins only. Link to a record without hardcoding its URL Take a URL from the record with getFullPath(), never from a path typed into the template. Get the record from an author-picked area, from a query by a stable attribute, or from a route name for module pages. Show content only on production Environment names are free text, so do not test for the word "production". Test that this is the site's primary environment and the request came to one of its own hostnames, once, in the base template. Add a per-site feature flag and read it in a template Site data is a per-site store of values an administrator edits in the admin without a deploy. A flag is one key; read it with _siteData.get(), and read the field you mean when the value is a structure. Register a page-specific JS bundle with a CSP nonce Build a separate entry, queue its URL from the template or component that needs it through _templateContext, and let the base template print every queued script once, with the nonce and the deploy hash. Cache-bust an asset URL Append the deployed commit to every built asset URL with getLastVcsHash(); it changes on every deploy. Uploaded files use the change-time setting, and replaced images clear their own cache.