Watch a live product demo 👀 See how Sanity powers richer commerce experiences

Creating an Inline-Block in Portable Text to Insert Current Date or Time

5 replies
Last updated: Aug 5, 2022
Here’s one I’m having a hard time with.
I would like to create an “inline-block” in my portable text, such that I could have a way to insert the current date or time as a block. As far as I can tell, I cannot do this as a standalone thing, I would have to annotate text and use a mark to say it should display the current date before it or instead of it.

Is there another solution here that I’m not thinking of?
Aug 5, 2022, 12:53 PM
I’m pretty sure you‘re correct, you’ll have to annotate the text and get rid of its content if you don’t use it.
Aug 5, 2022, 1:22 PM
gotcha, thank you for the reply. That’s what i ended up doing
Aug 5, 2022, 1:23 PM
You can make inline blocks though!
  type: 'block',
  of: [{type: 'currentDate' }] // <= must be an object type (I think)

Aug 5, 2022, 3:07 PM
object can type can also have an initial value that puts a predefined string
Aug 5, 2022, 3:07 PM
Juxtaposition may be helpful to underline this, because regular custom blocks can seem inline, whereas what
user Y
is saying is truly inline.
On the left is a similar example from the docs, juxtaposed on the right with a custom block that
follows after the editor block in the array that houses them, instead of being a specific of qualifier.
The ones he is showing you how to do are really powerful
because they can be right in the middle of text and I am always surprised to see how uncommon they are because of the utility they provide.
Aug 5, 2022, 6:02 PM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the 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.

Categorized in

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
After adding the subtitle and running this code npm run graphql-deploy It does nothingSep 15, 2020
how to limit a reference to just one entry in Studio reference input side versus the default as-many-entries-as-you-fill-in-an-array...Sep 18, 2020
Is it possible to fetch more than one "_type" using GROQ?Nov 2, 2020
I want to add a view with the Structure builder (S.view.component) where I list similar documents based on the title. What...Sep 23, 2020
Is there a structure builder example where the format of each preview for the document list is modified?Feb 3, 2021
I have an array of references to a country schema type but it always just returns NULL values for meJan 30, 2021
Hi, I need help with a query for getting the url of an image asset. Here is what I've been trying, but I only get the _ref...Dec 1, 2020
Sanity UI looks brilliant :smiley: Is something like the current date picker possible at the moment? I’m not sure if anicon...Dec 21, 2020
Hey everyone. I have been coding and may have potentially accidentally deleted something. Does anyone know how to resolve...Dec 26, 2020
Hello everyone and happy new year :raised_hands::skin-tone-2:, I have a problem with outputting Portable Text :disappointed:...Jan 1, 2021

Related contributions

Clean Next.js + Sanity app
- Template

Official(made by Sanity team)

A clean example of Next.js with embedded Sanity ready for recomposition.

Cody Olsen
Go to Clean Next.js + Sanity app

Blog with Built-in Content Editing
- Template

Official(made by Sanity team)

A Sanity-powered blog with built-in content editing and instant previews.

Go to Blog with Built-in Content Editing