Created
June 27, 2017 11:37
-
-
Save rexxars/9075a6f6d31e85c55948ed10e9da6142 to your computer and use it in GitHub Desktop.
Image renderer, PHP-client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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