Packbase SDK

pb.customFeeds

Create, pin and render custom feeds, and write Handlebars templates for them.

A custom feed is a theme repository (kind: 'feed') that declares search queries and the Handlebars templates that lay out their results. Reading and rendering use pb.search(): the feeds model lists feeds, and runFeed() renders one. pb.customFeeds holds the writes. Every write requires a signed-in session.

Writes

const { ,  } = await ..({
  : 'Art from my circle',
  : 'Image howls tagged #art from people I follow',
})

await ..(, { : false }) // returns the SearchFeed row
await ..()
await ..([])
await ..()
await ..()
MethodRouteReturns
create({ display_name, description? })POST /feeds/custom{ id, repository: ThemeRepositoryStatus }
update(id, { listed? })PATCH /feeds/custom/:idSearchFeed
delete(id)DELETE /feeds/custom/:idvoid
pin(id) / unpin(id)PUT / DELETE /feeds/custom/:id/pinvoid (idempotent)
reorder(ids)PUT /feeds/custom/pins/ordervoid
editors(id)GET /feeds/custom/:id/editorsCustomFeedEditor[]
addEditor(id, username)PUT /feeds/custom/:id/editorsCustomFeedEditor[]
removeEditor(id, userId)DELETE /feeds/custom/:id/editors/:userIdvoid

display_name is 1 to 60 characters, and description is up to 300. Only the owner can update or delete a feed; built-in feeds can't be deleted. Each member can own up to 20 feeds and pin up to 50. An unlisted feed stays out of the directory, but it still runs, you can still pin it from its link, and it stays in readers' pinned tabs.

Feeds are usually edited in Atelier, which previews the working copy live. Publishing uses the theme repository flow: edit and commit through pb.themes('feed', id), wait for validation, then call publish(). Publishing syncs the feed's display name and description from feed.json.

Editors and staff

A feed's owner can let other members edit its template: change the repository in Atelier, preview it and publish. Add them by username with addEditor(); a feed can have up to 20 editors. Staff can edit every feed. Only the owner and staff change the editor list, and an editor can remove themselves. Unlisting and deleting stay with the owner.

Search rows carry can_edit for the reader, and from('feeds').where({ editable: true }) lists the feeds the reader owns or edits, drafts and unlisted ones included.

Built-in feeds

Following, Discover and Everything are ordinary custom feeds owned by the Packbase system profile, with system_key set to 'following', 'discover' or 'everything'. They have a default_position: each member gets them pinned once, ahead of their own pins, the first time their pins are read. Unpinning one sticks, and it can be pinned again like any feed. Guests see them too: search for from('feeds').where({ default_position: { not: null } }).orderBy('default_position', 'asc'). Staff edit them in Atelier like any feed. Discover orders its posts by network_rank; see the search reference.

Repository layout

feed.json          # manifest (required)
templates/feed.hbs # whole-feed layout (required)
templates/*.hbs    # partials, referenced as {{> name}}
styles/*.css       # scoped to the feed container
assets/*           # images

feed.json declares up to 6 named queries in the POST /search grammar, including viewer placeholders. primary names the posts query that pages. The other queries run once, on page 1. cover and icon name images in assets/ that the directory shows once the revision is published; search results return them as cover and icon paths. pagination chooses "infinite" scrolling (the default) or "paged" Previous/Next pages; every CustomFeedRun reports it, so render the matching controls. See Manifests for the full reference and Templates for the whole template language.

Manifest keyTypeDefaultDescription
packbaseManagesWidthbooleantrueKeep Packbase's centered max-w-2xl width; set to false to let the template use the full available width.
{
  "name": "Art from my circle",
  "description": "Image howls tagged #art from people I follow",
  "primary": "posts",
  "pagination": "infinite",
  "packbaseManagesWidth": true,
  "cover": "assets/cover.png",
  "icon": "assets/icon.png",
  "queries": {
    "posts": {
      "from": "posts",
      "feed": true,
      "where": {
        "parent": null,
        "tags": { "has": "art" },
        "asset_types": { "has": "image" },
        "user_id": { "in": { "$viewer": "following" } }
      },
      "orderBy": { "created_at": "desc" },
      "take": 30
    }
  }
}

Template guide

Templates use Handlebars. The app renders them in a sandboxed frame with no network access, sanitizes the HTML output, and then mounts it in <div data-custom-feed="<id>">. Feed CSS is always scoped to that container.

Context

A feed's templates render with FeedTemplateContext. The app builds it from a CustomFeedRun:

import type { FeedTemplateContext } from '@packbase/sdk-ts'
type _Context = FeedTemplateContext
type _Context = FeedTemplateContext
FieldDescription
feed{ id, display_name, description, owner, pinned, pin_count }
viewer{ signedIn }. Viewer identity is never exposed.
resultsThe declared queries by name, such as results.posts
pageThe current page, starting at 1
hasMoreWhether another page exists

Placeholder expansions are never included in the context.

Helpers

TEMPLATE_HELPERS lists every helper a template can call. The server rejects any other helper when it validates the revision.

GroupHelpers
Handlebars built-insif, unless, each, with, lookup, log
Comparison and logiceq, ne, gt, gte, lt, lte, and, or, not
Valueslength, json, date, relativeTime, number, truncate, lower, upper, plural
URLsurl, asset, howlUrl, profileUrl, packUrl, mediaUrl

URL helpers return only same-origin app paths, theme asset URLs, or https: URLs.

Built-in partials

BUILTIN_PARTIALS are native components that the app mounts over the rendered markup. Pass the howl as the partial's context, as in {{> howl this}}.

PartialRenders
howlThe full native howl card
likeThe like button, with the emoji, count and the reader's like state
replyButtonThe reply button and composer
menuThe howl's dropdown menu
shareThe share button
mediaThe howl's media and viewer
authorThe author's name and avatar

Partials from templates/*.hbs and inline partials are also available. Repository partials use their file name, such as {{> card this}} for templates/card.hbs.

Actions

Any element can carry data-pb-action with data-pb-howl="{{id}}" to run the same handler as the native card:

data-pb-actionEffect
likeLikes or unlikes the howl
replyOpens the reply composer
openOpens the howl in the app, without reloading the page
shareShares the howl
profileOpens the author's profile

Same-origin links in the container open inside the app.

Starter template

{{#each results.posts}}
  {{> howl this}}
{{/each}}

{{!-- A hand-built card:
<article>
  {{> author this}}
  <p>{{body}}</p>
  {{> like this}}
  <button data-pb-action="open" data-pb-howl="{{id}}">Open</button>
</article>
--}}

Add ?theme=off to a feed URL to show its posts in the default list.

On this page