Question

I'm new to Drupal 7 and I'm looking to replace the frontpage's default main content block with an equivalent block generated from Views (gaining more control over the block in doing so).

I have successfully generated the new frontpage block in Views and added it to the content section however now the homepage displays both the original and the new views block.

Attempting to remove the main content block by configuring it to not display on <front> does not work and for now the only workaround I have found is the following CSS:

.front #block-system-main {
  display:none;
}

I'd prefer a less hack-like solution. Can anyone suggest one?

Was it helpful?

Solution

Sorry, but that's not the way to do it.

Instead of creating a block display in Views, create a page display. Choose a path for your views page, for instance "home", and save the view. Next you go to /admin/config/system/site-information and change the value for 'Default front page' (it probably says "node" now) to the path you chose for your view ("home").

When you follow this approach, the main content on your front page will be the view.

OTHER TIPS

First of all you have to remove the default home content, here is the way to do that:

<?php
function MYTHEME_OR_MODULE_preprocess_page(&$variables) {
  if ($variables['is_front']) {
    $variables['title'] = '';
    unset($variables['page']['content']['system_main']['default_message']);
  }
}

Remove homepage default content

Then create the block view that you want.. then go to blocks.. show this block view in "content" region .. and restrict this content to "only the following pages" and write <front>

That's it


Although not a common approach, you can embed a view as main content block on frontpage. Views has the flexibility to do it either way in a wink. I suspect you misconfigured the block removal step you were trying or ... merely had to clear the cache to obtain the same result.

To be fair on the accepted answer, that approach is the usual way of doing it. End result is identical.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top