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?
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.
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) }
Commented
Dec 4, 2013 at 5:13
MYTHEME
by MYMODULE
right ?
Commented
Aug 14, 2018 at 2:54
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)
}
}
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;}
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).
I have a template for all new projects that contains:
That's it, I don't have to deal with the whacky default node page ever again.
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']);
}
}
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:
/admin/structure/views/view/frontpage
(to edit the view named "Frontpage").To verify your changes, browse to front page. If needed repeat the steps above to further tune the message.
hook your page.tpl.php to page--front.tpl.php and do whatever you want enjoy hooking :-)
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.
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:
$page['content']
.
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!
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
you can use String Overrides Module String Overrides for replace
"No front page content has been created yet in front page" to ""
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!!
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']);
}
}