Skip to content

Instantly share code, notes, and snippets.

@rexxars rexxars/example.php
Created Jun 27, 2017

Embed
What would you like to do?
Image renderer, PHP-client
<?php
require_once './vendor/autoload.php';
$client = new Sanity\Client([
'projectId' => '3do82whm',
'dataset' => 'production',
]);
$doc = $client->getDocument('47abbe60-f184-4eff-99e0-3a85c5c07c3a');
$html = Sanity\BlockContent::toHtml($doc['body'], [
'serializers' => [
'image' => function ($node) use ($client) {
$image = $client->getDocument($node['attributes']['asset']['_ref']);
$url = $image['url'] . '?w=640';
return '<img src="' . $url . '">';
},
'code' => function($node) {
return '<code />';
}
]
]);
echo $html;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.