Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

content-sdk-app-router-component-variants

/content-sdk-app-router-component-variants

Obsługuje warianty komponentu w aplikacji Content SDK App Router: jeden typ z kilkoma prezentacjami wybieranymi przez wariant lub dane.

Licencja
Apache-2.0
Ostatnia zmiana repozytorium
05.11.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
2
Przestarzałość

Brak sygnałów. Repozytorium zmienione 05.11.2026, bez odwołań do wycofanych modeli i API.

Licencja

Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.

Co robi i kiedy

Obsługuje warianty komponentu w aplikacji Content SDK App Router: jeden typ z kilkoma prezentacjami wybieranymi przez wariant lub dane.

Oryginalny opis (EN)

Component variants in a Content SDK App Router app — one component type with several presentations, selected by rendering variant or data. Use when the user asks for variants, versions, variations or multiple renderings of one component.

Jak działa

  1. When to use
  2. How to perform
  3. Worked example
  4. Hard Rules
  5. Stop Conditions
  6. References
Sekcje z nagłówków SKILL.md, w oryginale · 62 linii, 582 słów
Podgląd SKILL.md
---
name: content-sdk-app-router-component-variants
description: "Component variants in a Content SDK App Router app — one component type with several presentations, selected by rendering variant or data. Use when the user asks for variants, versions, variations or multiple renderings of one component."
license: Apache-2.0
compatibility: "Requires @sitecore-content-sdk/* packages, Next.js 13+, and access to a SitecoreAI Edge endpoint with valid Edge context values (SITECORE_EDGE_CONTEXT_ID etc.)."
metadata:
  author: hahn-solo
  version: "0.7.1"
  upstream_repo: Sitecore/content-sdk
  upstream_commit: 70eccc43
  upstream_name: content-sdk-component-variants
  upstream_path: packages/create-content-sdk-app/src/templates/nextjs-app-router/.agents/skills/content-sdk-component-variants/SKILL.md
---

# Content SDK Component Variants (App Router)

One component definition can have multiple presentations or data-driven variants. Keep registration and layout aligned. This app does not use getComponentData; layout/placeholder data comes from getPage.

## When to use

- User asks for different "variants," "versions," or "presentations" of a component.
- Task involves rendering the same component type with different layouts or props based on data (e.g. variant field or style).
- User mentions "component variants," "variations," or "multiple renderings."

## How to perform

- Prefer one component that accepts variant/style via props and branches internally; or multiple map entries if the app pattern uses one key per variant. Use layout/fields/params for variant; register in the correct component map (Server or Client). Align with existing app convention.

## Worked example

The SDK resolves a variant from the rendering's `params.FieldNames` to a **named export**, case-sensitive. Same `componentName`, one folder, one file per variant (`<Name>.<Variant>.tsx`); `generate-map` merges every variant's exports into a single map entry.

```tsx
// src/components/Promo/Promo.Card.tsx — a variant of Promo
import { JSX } from 'react';
import type { PromoProps } from './Promo';

export const Card = ({ fields }: PromoProps): JSX.Element => (
  <article className="promo-card">{/* card-specific layout, same fields */}</article>
);
export default Card;
```

```ts
// .sitecore/component-map.ts — `sitecore-tools project component generate-map` merges variants
import * as Promo from 'src/components/Promo/Promo';          // provides the default fallback
import * as PromoCard from 'src/components/Promo/Promo.Card'; // exports `Card`

export const componentMap = new Map<string, NextjsContentSdkComponent>([
  // main module spread LAST so its `default` wins as the fallback; `Card` stays a named export
  ['Promo', { ...PromoCard, ...Promo }],  // named export `Card` + default fallback under ONE componentName
]);
```

Resolution: `FieldNames: "Card"` → `component.Card`; empty / missing / `"Default"` → `component.default` fallback; any unmatched name → `<MissingComponent>` + console warning (case-sensitive: `"card"` ≠ `"Card"`). The variant also needs a CMS **Headless Variant** item to appear in the Pages dropdown. CM-side, a raw `__Renderings` write stores the variant **item's GUID** in `FieldNames`, not its name. Once any variant item exists, a missing `FieldNames` resolves to the alphabetically first variant, not `Default`. Full runtime contract + failure modes: `content-sdk-variants-vs-siblings`.

## Hard Rules

- Prefer a single component registration that accepts variant/style data (e.g. params or fields) and branches internally, over multiple map entries for the same logical component unless the app pattern uses separate registrations per variant.
- Use props (fields, params) from layout to decide variant; do not rely on global state or URL for variant selection when data comes from Sitecore.
- Register in `.sitecore/component-map.ts` (Server) or `.sitecore/component-map.client.ts` (Client) as appropriate. If the app uses one key per variant, register each; if one key with variant param, single registration. Follow existing app convention.
- Keep the maps in sync via `npm run sitecore-tools:generate-map` (it also runs on `npm run dev` / `npm run build`) rather than editing them — the generator merges every `<Name>.<Variant>.tsx` export into the one map entry, which is easy to get wrong by hand.

## Stop Conditions

- Stop if the variant model (one registration vs many) is unclear; ask or follow the app's existing pattern.
- Do not add new component map entries without ensuring layout and editing can provide the corresponding data.
- Do not assume variant field names (e.g. "variant," "style") without checking the layout definition.

## References

- Runtime-verified deep dive with the failure modes (variant vs sibling, the file convention, `MissingComponent` on a miss): `content-sdk-variants-vs-siblings`.
- [Content SDK skills overview](https://github.com/Chris1415/sitecore-skills-pocs#skills-by-cluster).
- [Official Content SDK docs](https://doc.sitecore.com/sai/en/developers/content-sdk/sitecore-content-sdk-for-sitecoreai.html).

Wersje

W bazie nie ma innych skilli o nazwie content-sdk-app-router-component-variants.

Migawka bazy z 13.11.2026 · wersja paczki ef95f64ced22 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.