Embed Content
Learn to Embed Content to Unstructured Text Such as Markdown or Rich-Text to Close the Gap Between Unstructured Content and Structured Content
Last updated
Learn to Embed Content to Unstructured Text Such as Markdown or Rich-Text to Close the Gap Between Unstructured Content and Structured Content
Last updated
This documentation is based on the FoodCrunch use case. Please open the link below alongside this page to understand the examples.
Introduction and Use CaseWhen a content author writes an article about new food startups or a review for a product sold by a startup, they might want to add startup information to the article. As the article is unstructured and just Markdown or rich-text, there are limited options mentioned below and none of them really work:
The author can copy and paste the startup information to the article. When the information about the startup is updated at a later date, the article will contain outdated information.
It's possible to use a special placeholder in the Markdown to reference the startup and ask the developers to resolve this reference in the UI.
The developers can build a complex schema, for example with arrays to structure the article.
As none of the options are practical and convenient, this feature has been added.
To use this feature follow the steps below:
By editing the string field, you can decide which schemas can be embedded. Set Markdown (1) as the editor as it provides easy options to insert contents. Next, check Is embedding contents and assets (2) and select the schema.
In this example, we only allow embedding of contents from the startups
schema.
We can now use the Markdown editor to add links to other content items. To do so, click the Insert Contents (1) button in the editor.
The string field must be set to Markdown editor to see the insert contents button.
On the popup window, select the entries you wish to link by checking the box (2) next to them and click Link selected contents (3). Refer to the example screenshot below, here we are selecting a couple of startups:
The result should be two links appearing in the Markdown editor. An example screenshot is provided below for reference:
Use the new GraphQL structure to fetch the text and references. When you allow embedding, the structure of the GraphQL response changes and you can fetch the text and the references with a single request:
In the frontend both of the pieces of information can be used together to render the embedded content. In this sample code we've used react and react-markdown for this purpose. We can hook into the rendering process and render custom components for links.
At this point, it's important to check if the link is referencing a content item and if this content item is part of the references. Then it's possible to render the startup.
As Markdown is unstructured a regular expression must be used for this. The result is an article with embedded startup information.
This feature gives the content authors a lot more flexibility and simplifies the schemas in question.
A sample for this feature is available in GitHub: https://github.com/Squidex/squidex-samples/tree/master/jscript/react/sample-hotels.
This sample does not use the FoodCrunch use case but can be used as a reference to understand how it is implemented.
The template for the schemas and sample content is also available under: https://github.com/Squidex/templates/tree/main/sample-hotels