16

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?

2
  • I have exactly the same issue.
    – JW.
    Commented Oct 15, 2015 at 19:27
  • I don't have enough reputation to answer this question. But I wanted 2 'view lists as blocks' and no other content so here is an alternative solution: drupal.org/node/2089911#comment-7868495 (then show the list or lists as blocks)
    – JW.
    Commented Oct 15, 2015 at 20:21

3 Answers 3

24

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.

6
  • Ah I see.I have tried your suggestion it works perfectly and seems very obvious now. Thanks marc.
    – irishbuzz
    Commented Mar 21, 2011 at 21:45
  • You're welcome, glad I could help. Commented Mar 21, 2011 at 22:23
  • Thanks, definitely the cleanest solution on here! Others were talking about mucking around in the core code or setting up stylesheets. I knew there had to be an easier way.
    – Organiccat
    Commented Aug 11, 2012 at 15:11
  • 1
    @MarioAwad technically, yes. That's how the Drupal front page setting works. However, if all modules correctly build URL's and links with the url() and l() functions, Drupal will take care of it and link to www.example.com whenever www.example.com/path/to/view is given. If you like, the Global Redirect module will redirect to the front page in the case that someone would explicitly request the full path. Commented Mar 25, 2015 at 10:49
  • 1
    @marcvangend thanks for the extra clarifications and the pointer towards Global Redirect which solves the double path issue. Cheers.
    – Mario Awad
    Commented Mar 25, 2015 at 12:53
2

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


0

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.

1
  • I think it is a bug in Drupal because I, too, tried that 'block removal step' and it simply did not work.
    – JW.
    Commented Oct 15, 2015 at 19:29

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