Skip to main content

Filters

Build navigation and faceted filtering from a single, localized content filter tree.

More information about the module's user interface https://doc.oneentry.cloud/docs/category/filters (opens in a new tab)


The Filters module retrieves a content filter by its marker. A content filter is a curated, localized tree of items that can mix pages, products, attributes, discounts, bonuses, payment methods and custom entries in one structure.

You define the tree once in the OneEntry admin panel and pull it into your app to render navigation, faceted filters or curated lists. The SDK is read-only: it retrieves filters by marker.

Quickstart​

Initialize the module from defineOneEntry:


const { } = defineOneEntry(
, {
}
);

Fetch a filter by marker and walk its items tree:

// Fetch the "filter" content filter, localized to English.
const filter = await Filters.getFilterByMarker('filter', 'en_US');

if ('statusCode' in filter) {
console.error(filter.message); // IError, e.g. 404 for an unknown marker
} else {
console.log(filter.localizeInfos.title);

filter.items?.forEach((node) => {
console.log(node.type, node.marker ?? node.url, node.children?.length ?? 0);
});
}

Markers and localization​

Every filter has a unique marker (for example, filter). Reference filters by marker, never by their display title. The response is localized to the langCode you pass (en_US by default), so request the filter in the user's current language. Filters change rarely, so they're good candidates for caching.

Items tree​

The items array is a tree. Regular and custom items share the same array, and each node can have nested children with the same node shape. To render multi-level filters and menus, walk items recursively.

Each node has a type that points to something in your project:

  • page: a link to a page (exposes a url)
  • product: a product entry
  • attribute: an attribute to filter by
  • discount / personal-discount: a discount entry
  • bonus: a bonus entry
  • payment-method: a payment method
  • admin: an admin entry
  • custom: a custom entry you defined

Every node carries localized info in localizeInfos. Page nodes (type: "page") expose a url; custom nodes carry neither url nor marker; other node types reference their entity by marker.

Node value​

The value field holds a unified node value, typed string | string[] | null. It's null when the node has no value (a page, for example). A range attribute returns an array of the values that fall within the range. Other node types return a single string: for an attribute, the code of the selected list value or the stored value (for example "51"); for discount / personal-discount / bonus, the discount value; for product / admin / payment-method, the object id; for custom, the value you entered.

const value = node.value;
const values = Array.isArray(value) ? value : value == null ? [] : [value];

Methods​

MethodDescription
getFilterByMarker()Get a content filter by its marker

  • Pages: pages referenced by filter nodes
  • Products: products referenced by filter nodes
  • AttributesSets: attributes referenced by filter nodes