second-page.html
within this website)<a>
nor <img>
tags are allowed as top level elements in rich text.
For the <img>
tag, you can easily convert it to an asset in Kontent.ai by changing it to a <figure>
tag with an external ID: <figure data-asset-external-id=\"rich-text-asset\"></figure>
. As you know if you've imported linked content, Kontent.ai can store references to external IDs even for items that haven't been created yet. So you can always add in the asset later.
For the <a>
tag, you'll want to turn this into a component. This gives you the benefit of having a clear structure for your button that you can use repeatedly. You can then use the structured data for any presentation depending on the context instead of having a hard-coded link that can't work in all situations.
So instead of an <a>
tag, you'll use an <object>
tag defined based on components in Kontent.ai with a unique GUID you can generate yourself. The result will be something like <object type=\"application/kenticocloud\" data-type=\"component\" data-id=\"a2ee7bac-15ff-4dce-a244-012b9f98dd7b\"></object>
.
<a href=\"second-page.html\">
), the link would be assumed to be an external link and http://
would be added as a prefix (resulting in <a href=\"http://second-page.html\">
). To fix this, you want to change the link from an external link to an internal one.
You can again take advantage of references to external IDs while creating your internal link so that you can reference an item you'll create later. Just write your <a>
tag as follows: <a data-item-external-id=\"second-page\">
) (or whatever you want the other page to have as an external ID).
components
property of your rich text.
Your button has two elements: its text and the link to be opened. You created a Button content type to hold such components, so now you can use that type to hold your data. Use the external IDs you created when adding the type. A single component
object using the GUID from the rich text would look like this:
Now you can see the clear structure of your button, which can be useful when you implement such buttons in your app.
<h1>Lorem Ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur <a href="https://wikipedia.org">adipiscing elit</a>, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<a href="https://kontent.ai" class="cta">Buy me</a>
<p> Ut enim ad minim veniam, <a href="second-page.html">quis nostrud</a> exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p>
<ul><li>Lorem ipsum dolor sit amet</li><li>Consectetur adipiscing elit</li><li>Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</li> </ul>
<img src="https://kontent.ai/img/general/logos/kai-black-text.svg" alt="Kontent.ai" />
"<h1>Lorem Ipsum</h1>\n<p>Lorem ipsum dolor sit amet, consectetur <a href=\"https://wikipedia.org\">adipiscing elit</a>, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>\n<a href=\"https://kontent.ai\" class=\"cta\">Buy me</a>\n<p>Ut enim ad minim veniam, <a href=\"second-page.html\">quis nostrud</a> exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>\n<ul>\n <li>Lorem ipsum dolor sit amet</li>\n <li>Consectetur adipiscing elit</li>\n <li>Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</li>\n</ul><img src=\"https://kontent.ai/img/general/logos/kai-black-text.svg\" alt=\"Kontent.ai\" />"
"<h1>Lorem Ipsum</h1>\n<p>Lorem ipsum dolor sit amet, consectetur <a href=\"https://wikipedia.org\">adipiscing elit</a>, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>\n<object type=\"application/kenticocloud\" data-type=\"component\" data-id=\"a2ee7bac-15ff-4dce-a244-012b9f98dd7b\"></object>\n<p>Ut enim ad minim veniam, <a data-item-external-id=\"second-page\">quis nostrud</a> exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>\n<ul>\n <li>Lorem ipsum dolor sit amet</li>\n <li>Consectetur adipiscing elit</li>\n <li>Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</li>\n</ul><figure data-asset-external-id=\"rich-text-asset\"></figure>"
{
"id": "a2ee7bac-15ff-4dce-a244-012b9f98dd7b",
"type": {
"external_id": "button"
},
"elements": [
{
"element": {
"external_id":"button-text"
},
"value": "Buy me"
},
{
"element": {
"external_id": "button-link"
},
"value": "https://kontent.ai"
},
]
}
// Tip: Find more about JS/TS SDKs at https://kontent.ai/learn/javascript
// Using ES6 syntax
import { ManagementClient } from '@kontent-ai/management-sdk';
const client = new ManagementClient({
environmentId: '<YOUR_ENVIRONMENT_ID>',
apiKey: '<YOUR_API_KEY>'
});
const response = await client
.addContentType()
.withData((builder) => {
return {
external_id: 'simple-rich-text',
name: 'Simple Rich Text',
elements: [
{
name: 'Rich Text',
type: 'rich_text',
external_id: 'rich-text'
}
]
};
})
.toPromise();
// Tip: Find more about JS/TS SDKs at https://kontent.ai/learn/javascript
// Using ES6 syntax
import { ManagementClient, ElementModels } from '@kontent-ai/management-sdk';
const client = new ManagementClient({
environmentId: '<YOUR_ENVIRONMENT_ID>',
apiKey: '<YOUR_API_KEY>'
});
const response = await client.addContentType()
.withData(
{
external_id: "button",
name: "Button",
elements: [
{
name: "Text",
type: ElementModels.ElementType.Text,
externalId: "button-text"
},
{
name: "Link",
type: ElementModels.ElementType.Text,
external_id: "button-link"
}
]
}
)
.toPromise();
// Tip: Find more about JS/TS SDKs at https://kontent.ai/learn/javascript
// Using ES6 syntax
import { ManagementClient } from '@kontent-ai/management-sdk';
const client = new ManagementClient({
environmentId: '<YOUR_ENVIRONMENT_ID>',
apiKey: '<YOUR_API_KEY>'
});
const response = await client.upsertContentItem()
.byItemExternalId('simple-example')
.withData(
{
name: 'Simple example',
type: {
external_id: 'simple-rich-text'
}
}
)
.toPromise();