Learn how to make stress-free edits to published content without affecting the live version. Bryant walks you through how to enable content versioning in Directus and how to create and manage different versions of content.
Speaker 0: Alright. And welcome back to another episode of Short Hops. I'm your host, Brian Gillespie. In this episode, we are gonna cover content versioning. So what is content versioning?
Basically it allows you to do stress free editing on articles or content or pages, whatever you're serving up, that you've already published. Right? We've all been through it. Hey, we need to make some edits to a page. I need to be able to save those edits, but I don't wanna push those live until we get approval or we've had time to vet them out.
So content versioning allows you to basically make changes and edits without affecting the published version of a piece of content. Now how do we set that up? Right? I am in a sample Directus instance. This is one of my blog posts, a very nice piece by mister Carrot Gillespie, about steampunk rabbits and why they are the future of work.
So I've got some edits that I wanna make to this, but this is already published. So any edits that I make, if I save, could potentially show up live on our site. So content versioning to the rescue. How do we enable this? We go to our settings.
We go to the collection we would like to enable versioning for. And we'll go down to the settings for this and we'll find the content versioning header. We'll check the box. I'm sure you know what that will do. And now we'll go back to our post.
So at the top we can see now we have this little badge for main. So that is the main piece of content. That's the the main version that we are going to publish. So if I wanna make some changes here, I could just go and create a new version. This is, BG edits, And the key is important here.
We'll just call this Bryant's edits. Great. I've created that new version. Now I could go in and make all the changes I want here. This looks pretty good.
Okay. So what I can do now is save this version and I've got 2 versions here. I can see Bryant's edits. I could potentially, you know, send this to somebody on our team, ask them to review it. And then once I am ready to promote or publish this version, we've got a a function here called promote version.
So basically I'm gonna click promote version. This will then show me a difference between what is published and what is the, the edits that I'm making. And here I can confirm which version should be used for each of these individual fields. So if I don't want to overwrite the summary, I can, you know, use whatever is in the the main version here. Or likewise, in this case, I want to overwrite everything entirely.
I'll hit this and I've got the option to keep or delete. I could, keep this change, and now those changes that I make are now published in the main content version. Now when I'm accessing versions via the API, especially on like a front end or something, let's say I'm trying to fetch this piece of content. So I'm just gonna go to items slash posts and I could see the post here. Right?
If I were to go in and, you know, create a new version, let's just call it test version, and here's some more changes. We'll just save. Oh, actually, let's switch that. Here's the changes. And we'll save this version.
So now I'm working on the test version. If I run that API call again, you could see I don't see those changes. Right? But if I am calling an individual piece of content, I can add a version param to this. So I could say version equals test, and I could see here's the changes that we have.
Right? Great. So, that is content versioning. There's also a separate API endpoint for this as well if you wanna get all the individual content versions and it does support all the regular global parameters. So make sure you check out the documentation on this on how to leverage it further.
That's it for this episode. We'll catch you on the next one.