Skip to content

Instantly share code, notes, and snippets.

@rexxars
Created June 27, 2017 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rexxars/9075a6f6d31e85c55948ed10e9da6142 to your computer and use it in GitHub Desktop.
Save rexxars/9075a6f6d31e85c55948ed10e9da6142 to your computer and use it in GitHub Desktop.
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