Hey Prismic,
A thing I don't really get tbh is how to optionally query for content relationships from Prismic.
E.g. I have an "Are you interested in another article" kind of section where the editor inside the CMS can
- define the visibly of said section and
- choose / link to another article (via the standard content relationship field).
So far, so good. The way I am looking for that article inside my getStaticProps
:
const relatedArticle = await client.getByUID('journal_post', contact.data?.related_article?.uid)
(Recently added the ?
for testing purposes, but that does not help).
My issue now is, when the client chooses the section to be hidden
inside Prismic, they don't add those articles, but my site breaks, when there is not related Article (of course, because it's still looking for the related article inside my getStaticProps
query, as I can't do some optional queries in there)?
CMSes like Sanity or Craft do return empty objects (or let me get deeper when it exists) that don't break my code, but how to best do that with Prismic?
Thank you
—
Site note 1 — My quick and dirty solution for now is adding a note for the editor to still select an article, if the section is set to hidden
.
Side note 2 — You should really add a "real" help text option or "annotation component" for fields. I think this is one of the features I am personally missing the most. Putting important notes into the small grey text is something clients are often missing. Just think of a complex designed component where the client can choose between two complex layout solutions. Putting an explanation into the small grey text makes it quite unreadable.