Copied to clipboard

Flag this post as spam?

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


  • Stefano 61 posts 311 karma points c-trib
    Feb 21, 2017 @ 10:08
    Stefano
    0

    Static/dynamic error pages

    I like to make static .html pages for server errors, but want the content to still be dynamic and the links in the footer and header to be up to date.

    I wrote this code https://gist.github.com/StefanoChiodino/ad6f6860c235f4fd1d536fe53f887c2c that I'm sharing in case anyone was interested and would appreciate some feedback.

  • Alex Skrypnyk 5533 posts 20809 karma points MVP 3x admin c-trib
    Feb 21, 2017 @ 10:36
    Alex Skrypnyk
    0

    Hi Stefano

    Am I right that generation is performing each time node published or unpublished?

    Alex

  • Stefano 61 posts 311 karma points c-trib
    Feb 21, 2017 @ 10:38
    Stefano
    0

    Yes, it needs to be in order to update the header/footer navigation links! It's async so it shouldn't cause too much trouble.

  • Paul Wright (suedeapple) 229 posts 623 karma points
    Feb 21, 2017 @ 10:56
    Paul Wright (suedeapple)
    0

    A real "dirty" way to do this, would be to use some jQuery

    https://api.jquery.com/load/

    You can even have it load in a particular DOM element of the page. So you could load in your header/footer from an umbraco driven one.

    $( "#static-footer" ).load( "/umbraco-page/ footer" );

  • Alex Skrypnyk 5533 posts 20809 karma points MVP 3x admin c-trib
    Feb 21, 2017 @ 11:02
    Alex Skrypnyk
    1

    Hi Paul

    But if site will have application error, jquery code will return error too.

    Alex

  • Paul Wright (suedeapple) 229 posts 623 karma points
    Feb 21, 2017 @ 11:27
    Paul Wright (suedeapple)
    0

    Ahhh ok - I getcha :-)

    A good idea, but can see it slowing things down, if you're re-rendering this file on every "node save"

    Maybe only re-render it, if a node of a particular type is updated which affects the header/footer. E.g. a Global Settings node

  • Stefano 61 posts 311 karma points c-trib
    Feb 21, 2017 @ 11:46
    Stefano
    0

    It's very complicated and convoluted to know what exactly is in the header and footer, and it's hard to maintain. The event hook should be async so there should be no problem in the backend.

    Something I had to compromise that maybe you guys could help me with is I only managed to produce the .html with httpClient.GetAsync(errorPageAbsoluteUrl), while I'd like to produce the page with the template and IPublishedContent.

  • Alex Skrypnyk 5533 posts 20809 karma points MVP 3x admin c-trib
    Feb 21, 2017 @ 11:55
    Alex Skrypnyk
    1

    Stefano, you can use RenderTemplate method:

    library.RenderTemplate(pageId)
    
  • Stefano 61 posts 311 karma points c-trib
    Feb 21, 2017 @ 12:19
    Stefano
    0

    Thanks! Will that render the default template? That's perfect!

  • Alex Skrypnyk 5533 posts 20809 karma points MVP 3x admin c-trib
    Feb 21, 2017 @ 12:31
    Alex Skrypnyk
    100

    Stefano, yes, it will render the default template, but you can also specify template id if you need it.

    Hope it helped you.

    Alex

  • Stefano 61 posts 311 karma points c-trib
    Feb 21, 2017 @ 12:32
    Stefano
    0

    Awesome! Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft