Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jul 22, 2016 @ 14:28
    Jeroen Breuer
    0

    Preview all content

    Hello,

    Currently if you press the preview button only that node will be in preview mode. All other content is just the published version. We've got a huge website and we do many customizations in it. You might have heard of it ;-). For our preview we need all the content to be in preview mode. We know this might be slow, but we still need this.

    Anyone got some suggestions for this? I already have the code to convert an IContent to an IPublishedContent. I could check if the website is in preview mode and than use that, but maybe there are better ways to achieve this :-).

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jul 25, 2016 @ 07:42
    Jeroen Breuer
    0

    Not only the current node will be in preview, but also all child nodes. So by clicking preview on the highest node in the tree it seems that you can run your entire site in preview.

    Will do some more experiments :-).

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jul 26, 2016 @ 14:16
    Jeroen Breuer
    0

    Also make sure to upgrade to Umbraco 7.4.2 if you want to preview protected pages: http://issues.umbraco.org/issue/U4-4219#comment=67-27355

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Aug 01, 2016 @ 12:23
    Jeroen Breuer
    0

    Preview works in the frontend, but I would also like preview to work in the backend. So if I'm in preview mode it also shows those URLs in the backoffice. For now I checked the Umbraco source and it looks like I can check if the preview cookie is available. Would that be enough?

    Jeroen

  • David Peck 690 posts 1896 karma points c-trib
    Aug 01, 2016 @ 12:27
    David Peck
    0

    Could you replace the ContentFinderByNiceUrl with your own version that hits the ContentService rather than the cache? https://our.umbraco.org/Documentation/Reference/Routing/Request-Pipeline/IContentFinder

  • David Peck 690 posts 1896 karma points c-trib
    Aug 01, 2016 @ 12:28
    David Peck
    0

    Na. That won't work. Sorry - you've need to replace the UmbracoHelper as well I'd guess. You've got me.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Aug 01, 2016 @ 12:39
    Jeroen Breuer
    0

    The UmbracoHelper is only used in the frontend where InPreviewMode is already true. For the backoffice URLs replacing the ContentFinderByNiceUrl might actually work. But it's not the content finder that I need to replace but the UrlProvider.

    Jeroen

  • David Peck 690 posts 1896 karma points c-trib
    Aug 01, 2016 @ 12:48
    David Peck
    0

    OK, I've not properly understood where exactly in the back office you're referring to but I hope you make some progress with that approach.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Aug 01, 2016 @ 12:58
    Jeroen Breuer
    0

    I mean the URLs that you see in the backoffice. An unpublished node has no URL, but in preview mode it does, but still isn't displayed.

    Jeroen

  • David Peck 690 posts 1896 karma points c-trib
    Aug 01, 2016 @ 13:08
    David Peck
    0

    Well could you create a custom property editor which just displays what the URL is? You it would just get the UrlName of all ancestors, add it's own based on string.ToUrlSegment() (in Umbraco.Core), and join with a '/'. It's not the same as the Url but if it is just for information?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Aug 01, 2016 @ 13:48
    Jeroen Breuer
    0

    Already got something like that, but it's a complex website and I need to get the URLs from the UrlProviders.

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Aug 01, 2016 @ 19:46
    Jeroen Breuer
    100

    I got it working by having a custom property editor which get's the URLs from the front of the website. If the website is in preview it will return all the URLs. Even of unpublished ones.

    Jeroen

    enter image description here

  • keilo 568 posts 1023 karma points
    Aug 02, 2016 @ 08:46
    keilo
    0

    This looks cool!

    Can you share the code for this?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Aug 02, 2016 @ 09:14
    Jeroen Breuer
    1

    The UrlPreview code can be found in the 1-1 multilingual example: https://our.umbraco.org/projects/developer-tools/1-1-multilingual-example/

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Aug 04, 2016 @ 07:57
    Jeroen Breuer
    2

    Since preview for all content only works if you click preview on the highest node I wrote some code for that which can be triggered from every node.

    You can call this from a custom property editor. It will get the highest node and use that for preview.

    /// <summary>
    /// The url preview api controller.
    /// </summary>
    public class UrlPreviewApiController : UmbracoAuthorizedApiController
    {
        /// <summary>
        /// Update preview for the entire website.
        /// </summary>
        /// <returns>
        /// The <see cref="HttpResponseMessage"/>.
        /// </returns>
        [System.Web.Http.HttpGet]
        public HttpResponseMessage UpdatePreview()
        {
            var result = new HttpResponseMessage(HttpStatusCode.OK);
    
            // Get the highest node in the tree.
            // If we use this id for preview it will preview the entire website.
            var websiteId = this.GetWebsiteId();
    
            // Update the preview so we can see the saved changes.
            this.UpdatePreviewContext(websiteId);
    
            return result;
        }
    
        /// <summary>
        /// Checks if the user is currently in preview mode and if so will update the preview content for this item.
        /// If it's not in preview a new one will be created.
        /// </summary>
        /// <param name="contentId">
        /// The content id.
        /// </param>
        /// <remarks>
        /// This code uses some obsolete methods, but parts are copied from the Umbraco source and we keep it the same.
        /// </remarks>
        private void UpdatePreviewContext(int contentId)
        {
            // Get the preview id from the cookie.
            var previewId = this.Request.GetPreviewCookieValue();
    
            // If we have a GUID from the cookie use that.
            Guid id;
            var existingPreview = Guid.TryParse(previewId, out id);
    
            if (!existingPreview)
            {
                // If we don't have GUID from the cookie yet create a new one.
                id = Guid.NewGuid();
            }
    
            // Create the preview.
            var d = new Document(contentId);
            var pc = new PreviewContent(this.UmbracoUser, id, false);
            pc.PrepareDocument(this.UmbracoUser, d, true);
            pc.SavePreviewSet();
    
            if (!existingPreview)
            {
                // Create a new preview cookie if we don't have one.
                pc.ActivatePreviewCookie();
            }
        }
    
        /// <summary>
        /// Get the id of the website node. Don't use the ContentRepository because that only works with published content.
        /// </summary>
        /// <returns>
        /// The id.
        /// </returns>
        private int GetWebsiteId()
        {
            var websiteContentType = this.Services.ContentTypeService.GetContentType(Website.ModelTypeAlias);
            var website = this.Services.ContentService.GetContentOfContentType(websiteContentType.Id).FirstOrDefault();
    
            if (website != null)
            {
                return website.Id;
            }
    
            return -1;
        }
    }
    

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Aug 08, 2016 @ 13:08
    Jeroen Breuer
    0

    Has anyone ever tested if preview works when multiple users try it at the same time? It uses cookies so it should work. When I try to preview in 2 different browers the preview doesn't work anymore in the first browser when I open preview in the second browser.

    Jeroen

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Aug 08, 2016 @ 18:10
    Shannon Deminick
    0

    Is it simply because your 2nd browser that it doesn't work in doesn't have the preview cookie set?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Aug 09, 2016 @ 12:00
    Jeroen Breuer
    0

    Both browsers had the preview cookie set. The problem was that we were testing with the same user and that didn't work. So when testing in multiple browsers you should also login with different Umbraco users.

    Jeroen

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Aug 08, 2016 @ 18:14
    Shannon Deminick
    0

    Also pretty sure there's a setting somewhere to turn on full site preview... Or at least there was something along those lines at some point in time ;) i can see if i can find anything tomorrow if you don't beat me to it.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Aug 09, 2016 @ 12:01
    Jeroen Breuer
    0

    Preview for the full site would be cool, but my solution at https://our.umbraco.org/forum/extending-umbraco-and-using-the-api/78849-preview-all-content#comment-252857 also works fine :-).

    Jeroen

  • Simone Chiaretta 134 posts 541 karma points c-trib
    Sep 19, 2017 @ 13:18
    Simone Chiaretta
    0

    @shannon any chance you found how to turn on full-site preview at site level via settings? We are in the same situation but need to preview unpublished pages as anonymous users

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Dec 16, 2016 @ 08:21
    Jeroen Breuer
    0

    I blogged about how you can preview all the content. It also has a working example: http://24days.in/umbraco-cms/2016/umbraco-edge-case-stories/#preview

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft