can i manage (edit or add) contents of page builder while it is in unpublish condition?

Muhammad Kaleem asked on April 4, 2019 07:15

i want to ask can i manage my contents of pagebuilder when workflow is applied on page and page is in unpublish condition? if yes please share how it is possible?

Recent Answers


David te Kloese answered on April 4, 2019 16:01

Yes, you'll have to initiate the correct document.

Somewhere in your controller you might have something like:

HttpContext.Kentico().PageBuilder().Initialize(detailModel.DocumentID);

As long as you make sure that document ID is the correct unpublished version or correct workflowstep.

You can detect if you're in edit mode using something like:

bool previewEnabled = System.Web.HttpContext.Current.Kentico().Preview().Enabled;

Making the final result something like the following simplified code:

            if (previewEnabled)
            {
                // get last page version keeping workflow in mind
                ...
                detailModel = something();

                //initiate page builder
                HttpContext.Kentico().PageBuilder().Initialize(detailModel.DocumentID);
            }                
            else
            {
                // get last page published version
                ...
                detailModel = somethingElse();

                //initiate page builder
                HttpContext.Kentico().PageBuilder().Initialize(detailModel.DocumentID);                
            }
0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on April 4, 2019 18:15 (last edited on April 4, 2019 18:19)

I'm actually a little surprised though that the Page Builder is not showing the current checked out version, the Page builder should take care of that, is it not? WHen you edit widgets, aren't they saved to the current unpublished version?

As for the rest of your content, when getting your data, you need to modify your document query based on the environment. The precise code difference in your query would look like this:

if (EnvironmentHelper.PreviewEnabled)
            {
                RepeaterQuery.LatestVersion(true);
                RepeaterQuery.Published(false);
            }
            else
            {
                RepeaterQuery.PublishedVersion(true);
            }

If you want, here's a link to my Document Query Helper for MVC, it mimics the Portal Repeater and handles things, i have an EnvironmentHelper that gets the PreviewEnabled in a separate class (Just returns HttpContext.Current.Kentico().Preview().Enabled; )

https://pastebin.com/eDQrySSk

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on April 4, 2019 21:08

When using workflow your edit might not be the last published version. The page builder just initiates with whatever Document ID you give it. But that should match your view with the correct Widget Zones :)

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.