Discussion about adding a proper title and icons to a single page document in Sanity.io

21 replies
Last updated: Dec 14, 2022
Multiple questions thread:
1. How can i create a proper title for this single page document? Ive added a
title
, wont seem to be enough. 2. Why isn’t my icons working as the preview for the objects?
Dec 14, 2022, 7:21 PM

import {FaListUl, FaColumns} from 'react-icons/fa'
import {AiFillFileText, AiFillHome} from 'react-icons/ai'

export default {
  title: 'Content',
  name: 'contentList',
  type: 'array',
  of: [
    {
      type: 'introObject',
      name: 'introObject',
      title: 'Intro',
      icon: AiFillHome,
    },
    {
      name: 'listColumn',
      title: 'List Columns',
      type: 'object',
      icon: FaListUl,
      fields: [
        {
          name: 'listTitle',
          title: 'List Title',
          type: 'string',
          description: 'This title is for Sanity only.',
        },
        {
          name: 'listObject',
          type: 'listObject',
          title: 'List Columns',
          preview: {
            title: 'List Column',
          },
        },
      ],
    },
    {
      name: 'bodyObject',
      title: 'Body',
      type: 'object',
      icon: AiFillFileText,
      fields: [
        {
          name: 'bodyTitle',
          title: 'Title of Section',
          type: 'string',
          icon: AiFillFileText,
          description: 'This title is for Sanity only.',
        },
        {
          name: 'body1',
          type: 'body',
          title: 'Body',
        },
      ],
     
    },
    {
      name: 'column',
      type: 'column',
      title: 'Columns',
      icons: FaColumns,
    },
  ],
}
Dec 14, 2022, 7:22 PM
This is the entire content section.
Dec 14, 2022, 7:22 PM
And this is my About page.
Dec 14, 2022, 7:23 PM
Also forgot to add a picture of the single page title which is the About page^^
Dec 14, 2022, 7:25 PM
I’m pretty sure you can’t add icons to the fields. The icon is added to the array. I think the fields can have an icon added to the media section of the preview in the event the Array is it’s own object schema.

https://www.sanity.io/docs/previews-list-views
Dec 14, 2022, 7:32 PM
In order to add a title to that document, it’d need to be a document with a field that is an array within it.

import { UserIcon } from '@sanity/icons';


export default defineType({

name: 'documentExample',

title: 'Document',

icon: UserIcon,

type: 'document',

fields: [

// add title field

{

name: 'title',

title: 'Title',

type: 'string',

},

{

name: 'fieldArray',

title: 'Field Array',

type: 'array',

of: [

{

type: 'string',

},

],

},

],

}

);
Dec 14, 2022, 7:33 PM
If he would like to add a title but avoid making multiple documents, he can configure the desk structure afterwards.
Dec 14, 2022, 7:39 PM
Agreed.
Dec 14, 2022, 7:40 PM
Thought i sent the desk structure^^But its fixed by adding a title field.
Dec 14, 2022, 7:40 PM
This is how i solved the icons.
 preview: {
        select: {
          title:'listTitle',
        },
        prepare(selection: { title: TitledListValue }){
          const {title} = selection
          return {
            title: title,
            icon: FaListUl,
          }
        }
      }
Dec 14, 2022, 7:46 PM
It's interesting how you don't have it set up as a document though. I'm curious how it would show in the studio. Would it just show under the other lists, in the first column?
Dec 14, 2022, 7:47 PM
What isnt a document?
Dec 14, 2022, 7:47 PM
You have the type exported as an array instead of a document
Dec 14, 2022, 7:48 PM
I always thought you must first set it up as a type document when you export it to the index.js
Dec 14, 2022, 7:49 PM
Im guessing you guys didnt understand me. The first object ive sent is NOT the document
Dec 14, 2022, 7:50 PM
The first object ive sent is where i needed help with the icons (that’s on me for not being clear)
Dec 14, 2022, 7:51 PM
The object i sent is inside the document (document is the screenshot of «About»
Dec 14, 2022, 7:51 PM
The question I asked was just off topic. It was just more out of curiosity since I'm still learning about Sanity. But I understand now
Dec 14, 2022, 7:52 PM
My bad lol. but no its a document and not an array
Dec 14, 2022, 7:53 PM
the array you see is my
pagebuilder
Dec 14, 2022, 7:53 PM
lol your good. Thanks for clearing that up though🙏
Dec 14, 2022, 7:54 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?