ploneplone-4.xdiazo

Diazo - on error show message (when you get the content from a page)


Can we skip a diazo error and prevent page crash by replacing it with a nice message in page? Something like: Your content you want to show in this page is not created or published. Please check this section /source/homepage-content-sample-section.html.

<!-- Images slider section -->
<replace css:theme="[data-diazo='my-images-slider']"
         href="homepage-content/homepage-images-slider" method="document"
         css:content-children="#content-core" />
<drop css:content="#content-core [data-diazo='my-images-slider']" />

I have a page in Plone for each section in Homepage, that contains html code easy to edit. The problem is if a page is missing or private the homepage is broken.


Solution

  • Calling user-managed contents with href in a Diazo rule is like playing Russian roulette. If the page is not existing, there is not way to prevent the page crash.

    The best approach is to call a developer-defined URL in charge of retrieving the content if it exists and that will just gently return nothing if the content does not exists.

    Rapido is a very easy way to do that (you create a Rapido block which can be called like that: href="@@rapido/myapp/blocks/get-content-for-my-homepage", this URL will always work, your page will never crash whatever the users have done with the content).