I understand I'll need to add a v-if, BUT if what?
How do I do a check to see if there are no slices and to only show this code when there are slices.
Or alternativley how do I hide the above error when I intentionally add no slices to the document.
The use case here is part of keeping it simple for content writers.
We've created a content_type called 'posts' for blog posts.
The underlying component has a fixed header & footer and things like that.
The writer just edits the description to add their article details and then has the ability to add slices from the slice zone for themselves if they want to add a gallery or whatever.
If not the writer can just write the article and does not have to think which slices they should be adding beyond just writing the article.
Currently in our design work we have to ask the question
Is this a component that should always be on the page that we dont want content writers to have to think about or be able to remove? Or is this something that content writers will want to optionally add to a document?
That then determines whether we implement the thing as a slice or component.
I think this is arising as there seems to be some missing permissions that are meaning devs need to use adding components in code as a way of locking in mandatory components.
I might suggest that you review this area of why devs might still use components and add support so that more can be handled in slices.
To address where we dont want writers to HAVE TO rememember to add key slices to the page (aka a call to action that's just above the footer). It would be good within the Content Type editor to be able to add slices as DEFAULT ON. Eg they show anytime a new document is made but can be removed by the writer.
To address where we dont want writers to be able to remove components, it makes sense to have a permission level (Senior Writer/Editor whatever) where they can add slices to a content type that are compulsory and cant be removed by a writer (but they could).
With those permissions in place it removes any remaining logic to keep using components in the project which Im managing currently and hence this question.
I thought I had a solution but that didnt work.
Further reviewing the logic, isnt it that you wouldn't test for No Body, but rather that there is something in body.
Either way none of the solutions presented so far are working.
I'm seeking further guidance. Can you please test a solution yourself and advise.
Just wondering if there was any recent change on the Slice Machine, as I'm having the exact same issue as the user who open this thread. When I generate or publish to Netlify, that "Your SliceZone is empty" box is still showing (local and online). I double checked and the NODE_ENV variable is set to "production" so this should all be automatic and hide the box, correct?
The workaround I found was to use v-if="page.data.body.length" on the Slice Zone, where page contains the data coming from Prismic. v-if="!doc.body" wasn't working for some reason.
OK, I'm glad you got the workaround functioning at least.
I just want to be certain of the use case here, this is in a situation where you have a document where you aren't using the Slice Zone, but you might be using the Static zone of the document, is that correct?
Yes, exactly. I have some static fields that are being used and passed to the page and them I have an optional Slice Zone that might or might not have content.
OK, great thanks. I'm going to message the team and see if there's anything we can implement to do this check for you automatically and make a feature request for it.