Copied to clipboard

Flag this post as spam?

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


  • Jonathan Roberts 409 posts 1063 karma points
    Jun 23, 2017 @ 08:55
    Jonathan Roberts
    0

    Render page as HTML using a Page Version GUID

    Hi,

    is it possible to generate a full page with HTML markup using a Page Version GUID?

    Something like var htmlOfPage = Umbraco.RenderTemplate(pageId); but using the version GUID so I can see a full front end page of a previous version.

    Thanks

    Jon

  • Marc Goodson 2141 posts 14324 karma points MVP 8x c-trib
    Jun 25, 2017 @ 00:12
    Marc Goodson
    0

    Hi Jon

    You can use the ContentService to retrieve an IContent item representing a specific version of the content, from the database

    var cs = Services.ContentService;
    var specificVersion = cs.GetByVersion(Guid versionId);
    

    However your existing views will likely be working with IPublishedContent, rather than IContent.

    Jeroen Breuer wrote an article about converting IContent to IPublishedContent for edge cases...

    https://24days.in/umbraco-cms/2016/umbraco-edge-case-stories/#convert

    He's created an extension method called ToPublishedContent() in this gist

    https://gist.github.com/jbreuer/dde3605035179c34b7287850c45cb8c9

    so after retrieving your specific version using the content service, you could probably use this trick to turn it into IPublishedContent and work with your existing templates to generate a view of what the content looked like in the earlier version.

    regards

    Marc

  • Jonathan Roberts 409 posts 1063 karma points
    Jun 26, 2017 @ 13:28
    Jonathan Roberts
    0

    Thanks a lot for this.

    Is it then possible to create a HTML webpage from IPublishedContent.

    For example, should I call the function that I create IPublishedContent via JQuery or someway else?

    The render of the page needs to be dynamic so I cant pre code the page layout.

    The RENDERTEMPLATE result is ideally the return that I desire but instead of passing in the PageId I would pass in the Version GUID.

    Jon

Please Sign in or register to post replies

Write your reply to:

Draft