Modify blog posts

When editing a blog post, you must work with its master version. To modify a blog post, you must perform the following:

  1. Get the master version.

    Get the master version of the blog post. When you modify a blog post, you must not work on its live version.

  2. Get a temp version.

    Check out the master version to get a temp version of the blog post.

  3. Modify the temp version.

    Set the properties of the temp version to the new values.

  4. Update the master version.

    Check in the temp version to transfer the changes to the master version.

  5. Update the live version.

    Publish the master version to transfer the changes to the live version.

The example below shows you how to modify a blog post by the ID of its master version. For more information about working with the ID of the live version, see For developers: Edit content in For developers: Content lifecycle.

Modifying blog posts by the ID of its master version

The following code modifies a blog post by the ID of its master version.

Native API

First, you get an instance of the BlogsManager class. Then, you get the master version with the specified ID. Then, to get a temp version of the blog post, you call Lifecycle.CheckOut with the master version as an argument. You make all the modifications to the temp version. In this example you update the title of the blog post and its URL. Then, to transfer the changes to the master version, you call Lifecycle.CheckIn with the temp version as an argument. By default, when calling the CheckIn method the temp version gets deleted. To persist the changes, you call SaveChanges. Finally, to publish the master version, you call the MessageWorkflow method of the WorkflowManager class and pass the required parameters.

Fluent API

First, you check whether a blog post with the specified ID exists. Then, you get the singular blog facade of the master version with the specified ID. Then, you call the CheckOut method to get the facade for the temp version. You make all the modifications in the Do method of the temp facade. In this example you update the title of the blog post and its URL. Then, to transfer the changes to the master version of the blog post, you call CheckIn. To save the changes, you call SaveChanges. Finally, to publish the blog post, you call the MessageWorkflow method of the WorkflowManager class and pass the required parameters.

Was this article helpful?

Next article

Delete blog posts