Resolve rich text content
Is this page helpful?
<object type="application/kenticocloud" data-type="item" data-codename="my_tweet"></object>
<p>The used coffee grounds are retained in the filter, while the <a href="/articles/which-brewing-fits-you" data-item-id="65832c4e-8e9c-445f-a001-b9528d13dac8">brewed coffee</a> is collected in a vessel such as a carafe or pot.</p>
link
parameter to get more information about the linked content items.
// Tip: Find more about PHP SDKs at https://kontent.ai/learn/php
class CustomLinkedItemsResolver implements InlineLinkedItemsResolverInterface
{
public function resolveInlineLinkedItems($input, $item)
{
if(empty($item)){
return $input;
}
switch ($item->system->type) {
case 'tweet':
return "<blockquote class=\"twitter-tweet\" data-lang=\"en\" data-theme=\"".$item->elements->theme->value[0]->codename."\"><a href=\"".$item->elements->tweet_link->value."\"></a></blockquote>";
}
return $input;
}
}
// Tip: Find more about PHP SDKs at https://kontent.ai/learn/php
$client = new DeliveryClient("<YOUR_PROJECT_ID>");
$client->inlineLinkedItemsResolver= new CustomLinkedItemsResolver();
// Tip: Find more about PHP SDKs at https://kontent.ai/learn/php
// Retrieves a content item named 'My article'
$item = $client->getItem('my_article');
// Retrieves text from the 'body' Rich text element
$description = $item->body;
// Tip: Find more about PHP SDKs at https://kontent.ai/learn/php
class CustomContentLinkUrlResolver implements ContentLinkUrlResolverInterface
{
public function resolveLinkUrl($link)
{
// Resolves URLs to content items based on the Article content type
if ($link->contentTypeCodeName == "my_article") {
return "/articles/". $link->urlSlug;
}
// TODO: Add the rest of the resolver logic
}
public function resolveBrokenLinkUrl()
{
// Resolves URLs to unavailable content items
return "/404";
}
}
// Tip: Find more about PHP SDKs at https://kontent.ai/learn/php
$client = new DeliveryClient("<YOUR_PROJECT_ID>");
$client->contentLinkUrlResolver = new CustomContentLinkUrlResolver();
// Tip: Find more about PHP SDKs at https://kontent.ai/learn/php
// Retrieves a content item named 'My article'
$item = $client->getItem('my_article');
// Retrieves text from the 'body' Rich text element
$description = $item->body;