3

I have a node.

This node is set to be the 'Default 404 (not found) page' in

admin/config/system/site-information

I've got a custom block that I want to show within the node mentioned previous. I have used the 'restrict to certain pages' feature in configure block.

The problem is that it is not showing whenever I trigger a 404.

Can anyone offer a solution?

Thanks in advance.

2

The page you configure for a 404 code in admin/config/system/site-information is not a redirect to the new path, it reuses the original request and keeps the path. You see this in the browser, where the url remains unchanged when the custom 404 page is invoked. So you can't use the path from the 404 page to control the visibility.

See this feature request: Allow blocks to be configured to show/hide on 403/404 pages. I doubt that there will be any progress soon, because there is no activity for some time and the patch no longer applies.

You could implement the block visibility in a custom condition plugin or if you are looking for a simple solution do this in preprocess on theme level.

Or what I would prefer use a custom controller instead of a block, create a route to this controller and put this in the site settings.

0

Just override theme_page function then call phptemplate_page right after from your template.php file.

Remember to rename "YOURTHEME_page" with the name of your theme.

function YOURTHEME_page($content, $show_blocks = TRUE) {

// Set additional conditions to change $show_blocks if you want here.. // The following will always set $show_blocks to TRUE. $show_blocks = $show_blocks ? $show_blocks : TRUE;

// phptemplate_page is what gets called usually but the // theme function allows us to override it with the themes' name. // We're calling it directly here so we don't have to copy tons of code. return phptemplate_page($content, $show_blocks); }

To see why this works Look at this function. http://api.drupal.org/api/5/function/theme

If the only reason your trying to show the blocks is so it doesn't break your layout, then consider using the $layout var to set a body class. With some css knowledge it can be easily be fixed and you don't burden your sever with unnecessary load from rendering the sidebars.

  • Thanks for replying so quickly, it's very interesting to see how you can enable to rendering of blocks here. I'll give it a go and report back. Another thing is... any idea why some blocks generated using views are being rendered as opposed to normal custom blocks even though the show_blocks would be false by default? – cwiggo Dec 7 '16 at 11:58
  • Can you me any example for why some blocks generated using views are being rendered as opposed to normal custom blocks even though the show_blocks would be false by default? – Swapnil Bijwe Dec 7 '16 at 12:19
  • 1
    This doesn't seem to be for Drupal 8. – 4k4 Dec 8 '16 at 8:43
  • please check this link for drupal 8 drupal.org/node/2245767 – Swapnil Bijwe Dec 13 '16 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.