15

I only want blocks on the homepage. Because I don't have any nodes, and I want to keep the homepage as /node I am getting a "No front page content has been created yet." message on my page.

How do I get around this?

0

14 Answers 14

13

Who would have guessed? There's a module for that. Check out the Empty Front Page module. With only 10 lines of code, it must be one of the simplest modules out there.

5
  • As side note, this module will remove also the "Add new content" link which is not necessary, if the site is not going to have nodes.
    – apaderno
    Jan 20, 2013 at 8:09
  • 2
    Careful!! You don't need to add modules for small changes: you can override your template file and add the followning code : function MYTHEME_preprocess_page(&$vars) { if (drupal_is_front_page()) { unset($vars['page']['content']['system_main']['default_message']); //will remove message "no front page content is created" drupal_set_title(''); //removes welcome message (page title) } Dec 4, 2013 at 5:13
  • 5
    Careful? Is adding modules dangerous nowadays? In fact, I would be more careful about putting stuff like this in your theme. You can ask yourself the question "If I would ever choose another theme, should this change remain?" If the answer is yes, it doesn't belong in your theme. Dec 4, 2013 at 19:38
  • @HimanshuPathak It's probably better to avoid adding code to a theme just because it's easier, expecially when the behavior doesn't depend from a theme (which means the code you are adding to a theme should be added to every theme).
    – apaderno
    Aug 12, 2018 at 17:58
  • Thanks, in that case we need to replace MYTHEME by MYMODULE right ? Aug 14, 2018 at 2:54
9

You can do this in your theme's template file:

function MYTHEME_preprocess_page(&$vars) {
  if (drupal_is_front_page()) {
    unset($vars['page']['content']['system_main']['default_message']); //will remove message "no front page content is created"
    drupal_set_title(''); //removes welcome message (page title)
  }
}
3
  • Is it work for drupal8?
    – Guru
    Jan 22, 2016 at 9:19
  • though I haven't tried and I guess no Jan 28, 2016 at 10:47
  • I would not add code in a theme for something that I want independently from the theme I use for a site.
    – apaderno
    Jan 2, 2017 at 12:25
2

A quick CSS workaround to hide the "no content message" is simply by adding the following line in your CSS file :

 #first-time {display:none;}
2
  • 1
    This is a dangerous thing to do. It shows up in google results ;) Oct 21, 2014 at 9:58
  • I agree with you. this is not the best solution. this is a workaround. nothing more.
    – xaa
    Feb 18, 2015 at 11:36
1

The message "No front page content has been created yet." is shown from the page callback for the page you are using as front page, node_page_default(), which contains the following code.

  $select = db_select('node', 'n')
    ->fields('n', array('nid', 'sticky', 'created'))
    ->condition('n.promote', 1)
    ->condition('n.status', 1)
    ->orderBy('n.sticky', 'DESC')
    ->orderBy('n.created', 'DESC')
    ->extend('PagerDefault')
    ->limit(variable_get('default_nodes_main', 10))
    ->addTag('node_access');

  $nids = $select->execute()->fetchCol();

  if (!empty($nids)) {
    $nodes = node_load_multiple($nids);
    $build = node_view_multiple($nodes);

    // 'rss.xml' is a path, not a file, registered in node_menu().
    drupal_add_feed('rss.xml', variable_get('site_name', 'Drupal') . ' ' . t('RSS'));
    $build['pager'] = array(
      '#theme' => 'pager', 
      '#weight' => 5,
    );
    drupal_set_title('');
  }
  else {
    drupal_set_title(t('Welcome to @site-name', array('@site-name' => variable_get('site_name', 'Drupal'))), PASS_THROUGH);

    $default_message = '<p>' . t('No front page content has been created yet.') . '</p>';

    // …
  }

It is simply output because the site doesn't have nodes; the message is not related to the front page having (or not having) blocks.

If you want to keep that front page, but not seeing that message, you can implement the following hook in a module.

function mymodule_page_alter(&$page) {
  if (isset($page['default_message']['#markup']) && is_string($page['default_message']['#markup'])) {
    $page['default_message']['#markup'] = strtr($page['default_message']['#markup'], '<p>' . t('No front page content has been created yet.') . '</p>', '');
  }
}

The other alternative would be adding the following code at the end of the settings.php file.

$conf['locale_custom_strings_en'][''] = array(
  'No front page content has been created yet.' => '',
);

If you have other languages enabled in your website, you can add a similar entry for each language. For example, for Italian the code to enter would be the following one. (_en is replaced with _it.)

$conf['locale_custom_strings_it'][''] = array(
  'No front page content has been created yet.' => '',
);

Using this method, "No front page content has been created yet." would be replaced in every place where it is used, not just the front page. That string is normally used only in the front page, when the front page is the default one. I don't know if any other module using that string, but before replacing that string with an empty string with $conf['locale_custom_strings_en'][''], I would check there aren't any enabled modules that use it (except the Node module).

4
  • By the way, will this remove all the existing blocks from my homepage? Will I have to redo them again? Or will it only get rid of the message I don't want?
    – user12804
    Jan 19, 2013 at 3:54
  • Changing the page callback for a page doesn't change the blocks assigned to that page, so the answer is no to both the questions.
    – apaderno
    Jan 19, 2013 at 10:05
  • Sorry, another question. Which module should I put this in? If you want to keep that front page, but not seeing that message, you can implement the following hook in a module. function mymodule_page_alter(&$page) { if (isset($page['default_message']['#markup']) && is_string($page['default_message']['#markup'])) { $page['default_message']['#markup'] = strtr($page['default_message']['#markup'], '<p>' . t('No front page content has been created yet.') . '</p>', ''); } }
    – user12804
    Jan 20, 2013 at 7:37
  • You need to create a module, if you didn't already create one to customize the site.
    – apaderno
    Jan 20, 2013 at 8:10
1

I have a template for all new projects that contains:

  1. hook_menu() to make a new menu callback for a generic path like "home"
  2. The page callback for "home" which returns a string with one space in it ' ' (because Omega tries to be "smart" if you return an empty string)
  3. A strongarm export that sets the site homepage to my "home" url

That's it, I don't have to deal with the whacky default node page ever again.

1
  • Why do you export and not just set in your hook_enable() variable_set('site_frontpage', 'home'); just a note
    – Pan Chrono
    Mar 8, 2014 at 11:24
1

This is a cool snippet to get rid of this error without confusing with other contents placed in Content region. This will only hide this error and show the other contents normally.

This snippet is posted at Remove the "No front page content has been created yet." in the default Drupal installation.

/**
 * Implements template_preprocess_page().
 */

  function YOUR_THEME_preprocess_page(&$vars) {
   // Remove the "No front page content has been created yet.".
     if (isset($vars['page']['content']['system_main']['default_message'])) {
        unset($vars['page']['content']['system_main']['default_message']);
      }
  }
1

In Drupal 8, the same "No front page content has been created yet." is shown also, e.g right after you create a new site and visit its front page (homepage). But things have been simplified if you want to replace or remove it ... All that's needed is like so:

  • Navigate to /admin/structure/views/view/frontpage (to edit the view named "Frontpage").
  • Within "No results behavior", use the link "Global: Unfiltered text" to edit it. Either change the message (= "No front page content has been created yet.") to whatever you want, or just remove it entirely.
  • Don't forget to Save the changes.

To verify your changes, browse to front page. If needed repeat the steps above to further tune the message.

0

hook your page.tpl.php to page--front.tpl.php and do whatever you want enjoy hooking :-)

4
  • Thanks for that. How do I "hook" those two templates? Will this get rid of the "No front page content has been created yet." text on the homepage?
    – user12804
    Jan 18, 2013 at 12:22
  • no need to hook both templates just follow this steps:
    – Somik
    Jan 18, 2013 at 12:23
  • 1)copy total page.tpl.php content to your hooked front.tpl 2)then for check write your name or my name at the top and refresh your home 3)still if you cant find your name configuration->performance->clear all cache hard refresh front page
    – Somik
    Jan 18, 2013 at 12:26
  • 2
    If there are more than one theme enabled, I would rather not follow this method.
    – apaderno
    Jan 18, 2013 at 17:58
0

I'm not sure if there is a way to do this from Drupal's admin interface.

One way to accomplish this, that I know of, is to add an if statement to your page.tpl.php. Find a line like:

<?php print render($page['content']); ?>` 

...and change it to:

<?php if (!$is_front): ?>
  <?php print render($page['content']); ?>
<?php endif; ?>

That will basically print the main page content on all pages that are not the front page. But, this might leave you with a gaping hole in the middle of your page.

After commenting out content on Bartik theme.

So, you might do well to make a few other adjustments to your page.tpl.php and perhaps encompass more of the surrounding container tags. Further altering the tamplate, by putting the heading above the first sidebar for the home page:

<?php if ($is_front): ?>
  <?php if ($title): ?>
    <h1 class="title" id="page-title">
      <?php print $title; ?>
    </h1>
  <?php endif; ?>
<?php endif; ?>

...and moving the initial if statement and placing it just inside the content container:

<div id="content" class="column">
  <?php if (!$is_front): // Moved the if statement over here.... ?>
    <div class="section">
      <?php if ($page['highlighted']): ?>
        <div id="highlighted"><?php print render($page['highlighted']); ?>
        </div>
      <?php endif; ?>
      <a id="main-content"></a>
      <?php print render($title_prefix); ?>
      <?php if ($title): ?>
        <h1 class="title" id="page-title">
          <?php print $title; ?>
        </h1>
      <?php endif; ?>
      <?php print render($title_suffix); ?>
      <?php if ($tabs): ?>
        <div class="tabs">
          <?php print render($tabs); ?>
        </div>
      <?php endif; ?>
      <?php print render($page['help']); ?>
      <?php if ($action_links): ?>
        <ul class="action-links">
          <?php print render($action_links); ?>
        </ul>
      <?php endif; ?>
        <?php print render($page['content']); ?>
      <?php print $feed_icons; ?>

    </div>
  <?php endif;  // ...and closed it here. ?>
</div> <!-- /.section, /#content -->

...yielded the following results:

Removed the content and maintained the heading.

3
  • This is too excessive: It is not necessary to remove all the content of $page['content'].
    – apaderno
    Jan 18, 2013 at 17:57
  • What would you suggest instead?
    – user12804
    Jan 19, 2013 at 3:53
  • I would rather go with marcvangend's suggestion.
    – apaderno
    Jan 20, 2013 at 8:15
0

I don't know why you guys complicate it so much. (well I don't know if abd's ways work, but in case it didn't work, use the solution below.

in page.tpl.php you have to find this part of code:

(well I have this is mine Adaptive Theme 7x-3.2)

<?php if ($title): ?>
<h1 id="page-title">
<?php print $title; ?>
</h1>
<?php endif; ?>

All you have to do is delete it! All lines.

This part of php simply says:

If "title" exists, print it in H1 font size. It is printed on the website in the area the code is written in. In case of Adaptive Theme it's in Header area.

If you do not have page.tpl.php in your subtheme, you have to find it in the core theme, and then copy it to the same location as core theme, to your subtheme.

In AT it's /templates/page.tpl.php

it means that in your Adaptive theme subtheme you have to create folder named "templates" and then copy there page.tpl.php and then delete the part of code mentioned above.

It's important that you do not make any changes to the Core theme!

0

Place this code in page.tpl.php

if(drupal_is_front_page()) {

unset($page['content']['system_main']['default_message']);

}

Or

unset($page['content']['system_main']['default_message']);

In page--front.tpl.php

0

you can use String Overrides Module String Overrides for replace

"No front page content has been created yet in front page" to ""

0

Better to achieve this job is unset $page['content']['system_main']['default_message'] in hook_preprocess_theme or in the page.tpl.php or page--front.tpl.php.

find

<?php print render($page['content']); ?>

and replace with below code.

<?php  if(drupal_is_front_page()){
            unset($page['content']['system_main']['default_message']);
            } 
        print render($page['content']); 
    ?>

OR

  function MYTHEME_preprocess_page(&$vars) { 
       if (drupal_is_front_page()) { 
            unset($vars['page']['content']['system_main']['default_message']); //will remove message "no front page content is    created"
     }
    }

Enjoy!!

0

Hook with unset is the best way to do this.

use Drupal\views\ViewExecutable;

/**
* Implements hook_views_pre_render().
*/
function drupal_practice_views_pre_render(ViewExecutable 
&$view) {
  if($view->id() == 'frontpage' && $view->current_display == 
  'page_1' ){
    unset($view->feedIcons);
    unset($view->empty['area_text_custom']);
    unset($view->empty['node_listing_empty']);
  }
}

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