Working with Fields
Resolving content fields from documents is as easy as working with a vanilla PHP object, but still provides all the power of the official Prismic PHP Kit.
Content and Title fields
Resolving fields as HTML
Structured Text fields automatically resolve to HTML using __toString
casting. The following would resolve a field labeled blurb
as HTML.
<div>
{!! Prismic::getByUID('blog_post', 'post-1')->blurb !!}
</div>
Resolving fields as Text
In the above example, the blurb field is an object even though it resolves to a string, so you can still call it's methods.
<div>
{!! Prismic::getByUID('blog_post', 'post-1')->blurb->asText() !!}
</div>
or
<div>
{!! Prismic::getByUID('blog_post', 'post-1')->blurb->text !!}
</div>
Embeds
<div>
{!! Prismic::getByUID('blog_post', 'post-1')->video->asHtml() !!}
</div>
Links
Image Links
<img src="{{ Prismic::getByUID('blog_post', 'post-1')->image }}" width="{{ Prismic::getByUID('blog_post', 'post-1')->image->getWidth() }}">
>
Web Links
<a href="{!! Prismic::getByUID('blog_post', 'post-1')->link !!}">
A Link
</a>
<a href="{!! Prismic::getByUID('blog_post', 'post-1')->link !!}">
A Link
</a>
Images
In prismic images are divided into image views. This provides an easy way to different image dimensions to use in responsive srcsets. Every image will at least an image view called main
. Other image views are specified by the content type creator in Prismic.
Example
Prismic::getByUID('blog_post', 'post-1')
->thumbnail
->main
->getUrl()
Prismic::getByUID('blog_post', 'post-1')
->thumbnail
->retina
->getUrl()