Closed adear11 closed 1 year ago
Hi @adear11,
Do you mind reaching out to us on our live support chat on prismic.io?
I need to hear more about your use-case for this.
Thanks, Levi
Hey everyone,
do either of you (@levimykel @adear11) recall, if this conversation ever continued on prismic.io or the Forum? I would love to resolve this Issue 🙂
Best Constantin
@c0nst4ntin I don't remember at this point. This issue is so old that I think it's okay to close.
I will proceed to close this issue. If the topic comes up again, or @adear11 has anything new to add, we can re-open
This has been so long ago that I don't recall what, if anything, the resolution was. We still use Prismic, but the version of our application that this was opened for has since been replaced.
Is there a way to get a
Slice
from a document'sSliceZone
by referencing thesliceType
field?Looking at the code, the only obvious way I see to get to a particular slice in a zone is to reference it by array element. However, this has proven to not be reliable as adding a new slice to a Content Type changes the array element indexing.
In my case, I was developing a new Content Type. I had the Content Type set with one slice in the SliceZone. After a bit of development we decided to add a second slice. This action broke the pages that used this Content Type because the new slice became element '0' in the SliceZone's
Slices
array. This happening in development isn't that big of a deal, but if the situation arises that we want to modify a Content Type that has live, production content, it would be a real problem if referencing the slices by array index broke pages.Is it possible to do something like
$page->getSliceZone('my_type.field')->getSliceByType('my_type');
?As it currently is, the only way I can find to get to the slices is to do
$page->getSliceZone('my_type.field')[0]
, which, as I said, doesn't seem to be reliable.This seems like it would be an easy thing to implement. If this indeed isn't currently available, I'm happy to do a PR for it, but I wanted to make sure I wasn't missing something, and to also find out if there is a specific reason this isn't currently available.
Thanks.