By default a headless CMS is very decoupled from the frontends. This makes it much harder for your content editors, because they lack in understanding where a content is used. The main problem is that the frontend is not controlled by the headless CMS. Therefore integrated editing features are hard to implement. But Squidex has some features to make the live easier for your content editors.
This blog post is an excerpt from the documentation: https://docs.squidex.io/02-documentation/developer-guides/preview
In traditional content management systems you very often have a WYSIWYG (what you see is what you get) editor or other editing functionality where the editor can edit the content directly and understands how and where the content is used.
This is a challenge for a headless CMS, because of several reasons:
Squidex cannot solve all these problems for you. But with a little bit help from your frontend developers it can make the live easier for content editors.
In general we have several solutions to the problem which work together. They are are best described as Use Cases.
By default Squidex only provides published content items over the API, because the purpose is to only deliver finished content items that have followed a defined workflow.
But this means that a content editor cannot preview content items while he still edits them. Even if he would know where a content item would be used he cannot see it, because the application only gets published content items.
Therefore Squidex provides a special header.
Add the X-Unpublished = 1
header to all requests to retrieve unpublished content items.
Of course you do not want to show unpublished content items to your end users. Therefore it makes sense to use the header conditionally. The condition could depend on the user, environment or just a secret setting.
For the Squidex website we have just added a "top secret" query parameter to the blog page. When this query parameter is set to true, it will create add this header to the requests.
For each content item you can define preview URLs. These are just normal links that point to the place where a content item is used. If you have multiple environments or frontends you can also define multiple preview URLs.
You can define preview URL per schema.
The following example shows 2 preview URLs:
As you can see, you can use a placeholder with the JavaScript interpolation syntax. Therefore you can add content fields to the link dynamically. If you use a query string to enable unpublished content items, you could also add it to the URL.
If you open a saved content item, you will see the buttons with the preview URLs:
The following screenshot describes this feature best. The screenshot is from the Squidex website. The idea is to annotate content items on your website so that we can provide links to the Squidex Management UI where you can edit them.
As mentioned above Squidex has no control over your website, therefore you have to make a few changes to implement this feature.
This script is a little helper that provides the functionality. You have to add a script tag that points to https://cloud.squidex.io/scripts/embed-sdk.js. If you have installed Squidex on your own servers the URL is in general: https://YOUR_DOMAIN/scripts/embed-sdk.js
.
Just add the script tag at the end of your body
tag. This ensures that more important assets are loaded first and your website is as fast as possible.
The script is very small and has only 8.5kB at the moment, so it is not a problem to include it for all users. But if you want to optimize it further you can implement one of the mechanisms described under "Use Case 1".
The script works as followed:
When you query content items from the Squidex API you also get an edit token for each item.
Just annotate your elements with the edit token, for example you can show a list of blog posts like this. The actual template syntax might look different.
<div class="posts">
@foreach (var post in Posts)
{
<div class="post" squidex-token={@post.EditToken}>
<h3>{post.data.title.iv}</h3>
<p>{post.data.content.iv}</p>
</div>
}
</div>
The edit token is just a base64-encoded JSON object. Property names are shortened to keep the edit token as small as possible. If necessary you can also create the token manually.
More about the edit token can be found in the documentation: https://docs.squidex.io/02-documentation/developer-guides/preview
This is just the beginning. The Embed SDK is based on Preact (a smaller version of React) and can be easily extended to provide more integrated editing functionality for your content editors. Unfortunately there is no easy way to provide such functionality for other platforms such as mobile apps, but this does not mean that you cannot implement something like this on your own.