Panels 2: Creating a new front page with Views and Panels 2
Last modified: January 6, 2008 - 22:11
When you have tools as useful as Views and Panels 2, you'll want to be able to use them together. To figure out how to use them together, let's create a new front page. Drupal's standard front page is useful, but we want something a little more.
- The first thing to do is make sure you have both Views and Panels 2 installed. You don't need them all, but it's easiest to enable them all.
- The next step is to create the views we'll need. The first one we need, the front page view, is a sample view that comes with Views. Let's enable that.
- Click Views (Site Building > Views). This brings you to the Views management page. On the bottom, under the 'Default Views' heading, find the 'frontpage' default view, and click 'Add'.

- Click 'Save' at the bottom.
- Now, we need one more view. We'll use the simple monthly archive view. Import the code provided there using the 'Import' tab at the top of the Views management page, and copy and paste the code into the text box. Click 'Submit' at the bottom.
- The resulting View is fine; click 'Save' at the bottom.
- Now, on to the panel. Click Panel pages (Panels > Panel Pages).
- Before we can create the panel, you need to make sure Panels can "see" the content you've created. Click the 'Settings' tab at the top.
- Make sure everything under the 'New content behavior' heading is checked, especially the checkboxes next to 'New View' and 'New Legacy views'.
- Now, to create the panel. Click the 'Add' tab at the top of the page.
- Let's select the 'Flexible' layout, which allows us to create our own layout.

- Set the Panel name to: front_page
- Set the Page title to: Home
- Set the Path to: front

- Click 'Save' at the bottom.
- The 'Layout settings' tab that you are brought to looks intimidating, but we're just making a couple changes. The benefits of having a flexible layout, as we selected earlier, include being able to easily manipulate your panel to have any kind of configuration.
- Now, we want some custom dimensions for the panel, so set the Rows to: 1.
- In the first row (the previous changes haven't yet gone into effect), set the Columns to: 2.
- Again in the first row, set the Column titles to: Left, Right.
- Click 'Save' at the bottom (to refresh the page with the new settings).
- Set Width 1 to: 80, and Width 2 to: 20.
- Click 'Save' at the bottom. The final settings should look like this:

- Now we need to add a menu item. Click the 'Advanced' tab at the top.
- Click the checkbox next to 'Provide Menu'.
- Set the Tab Weight to: -10.
- Click 'Save' at the bottom.

- Click the 'Content' tab at the top.
- Click the plus sign on the left.
- Under the 'Views' heading, find and select the 'frontpage' view we added earlier. Click
- Click the checkbox next to 'Link title to view'.
- Click the checkbox next to 'Provide a "more" link that links to the view'.
- Click 'Add pane' at the bottom.
- Click the plus sign on the right.
- Under the 'Core blocks' heading, find and select 'Who's new'.
- Click 'Add pane' at the bottom.
- Click the plus sign on the right.
- Under the 'Core blocks' heading, find and select 'Who's online'.
- Click 'Add pane' at the bottom.
- Click the plus sign on the right.
- Under the 'Views' heading, find and select 'Monthly Archive'.
- Click the checkbox next to 'Link title to view'.
- Click 'Add pane' at the bottom.
- Click the plus sign on the right.
- Under the 'Core blocks' heading, find and select 'Recent comments'.
- Click 'Add pane' at the bottom.
- Click 'Save' at the bottom.

- Now, one last thing to do; we still have to make our front page the front page. Go to the 'Site information' menu (Administer > Site configuration > Site information).
- Set the Default front page to: front
- Click 'Save configuration' at the bottom.
- Click the 'Home' menu item we added on the menu.
- Voila, we have overrided the front page with a panel!

Here is the code for the monthly archive view, if you want to import it using the 'Import' tab at the top.
Here is the code for the front page view, if you want to import it using the 'Import' tab at the top:
$view = new stdClass();
$view->name = 'frontpage';
$view->description = 'The basic front page view.';
$view->access = array (
);
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = '';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = '';
$view->page_empty_format = '1';
$view->page_type = 'teaser';
$view->url = 'frontpage';
$view->use_pager = TRUE;
$view->nodes_per_page = '10';
$view->sort = array (
array (
'tablename' => 'node',
'field' => 'sticky',
'sortorder' => 'DESC',
'options' => '',
),
array (
'tablename' => 'node',
'field' => 'created',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->argument = array (
array (
'type' => 'node_feed',
'argdefault' => '2',
'title' => 'Drupal - ',
'options' => '',
'wildcard' => '',
'wildcard_substitution' => '',
),
);
$view->field = array (
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'promote',
'operator' => '=',
'options' => '',
'value' => '1',
),
array (
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
);
$view->exposed_filter = array (
);
$view->requires = array(node);
$views[$view->name] = $view;If you want to import a starting point for the front page panel, use the following code by clicking the import tab at the top of the Panel pages module:
$page = new stdClass();
$page->pid = 'new';
$page->name = 'front_page';
$page->title = 'Home';
$page->arguments = array();
$page->contexts = array();
$page->relationships = array();
$page->access = array();
$page->path = 'front';
$page->css_id = '';
$page->css = '';
$page->no_blocks = '0';
$page->menu = '1';
$page->menu_tab = '0';
$page->menu_tab_weight = '-10';
$page->menu_title = '';
$page->menu_tab_default = '0';
$page->menu_tab_default_parent_type = 'tab';
$page->menu_parent_title = '';
$page->menu_parent_tab_weight = '0';
$display = new stdClass();
$display->did = 'new';
$display->name = NULL;
$display->layout = 'flexible';
$display->layout_settings = array (
'width_type' => '%',
'percent_width' => '100',
'rows' => '1',
'row_1' =>
array (
'columns' => '2',
'width_1' => '75',
'width_2' => '25',
'names' =>
array (
0 => 'Left',
1 => 'Right',
),
),
'sidebars' =>
array (
'left' => 0,
'left_width' => 200,
'right' => 0,
'right_width' => 200,
'width_type' => 'px',
),
);
$display->panel_settings = array (
'style' => 'default',
'style_settings' =>
array (
),
'edit_style' => 'Edit style settings',
'individual' => 0,
'panel' =>
array (
'row_1_1' =>
array (
'style' => '',
'edit_style' => 'Edit style settings',
),
'row_1_2' =>
array (
'style' => '',
'edit_style' => 'Edit style settings',
),
),
'did' => '35',
);
$display->content = array();
$display->panels = array();
$pane = new stdClass();
$pane->pid = 'new-1';
$pane->panel = '';
$pane->type = '';
$pane->subtype = '';
$pane->access = array();
$pane->configuration = NULL;
$display->content['new-1'] = $pane;
$display->panels[''][0] = 'new-1';
$pane = new stdClass();
$pane->pid = 'new-2';
$pane->panel = 'row_1_1';
$pane->type = 'views';
$pane->subtype = 'frontpage';
$pane->access = array();
$pane->configuration = array (
'context' =>
array (
0 => 'empty',
),
'override_title' => 0,
'override_title_text' => '',
'css_id' => '',
'css_class' => '',
'view' => 'frontpage',
'type' => 'embed',
'link_to_view' => 1,
'more_link' => 1,
'feed_icons' => 0,
'use_pager' => 0,
'pager_id' => 1,
'nodes_per_page' => '10',
'offset' => '',
'panel_args' => 0,
'args' => '',
'url' => '',
);
$display->content['new-2'] = $pane;
$display->panels['row_1_1'][0] = 'new-2';
$pane = new stdClass();
$pane->pid = 'new-3';
$pane->panel = 'row_1_2';
$pane->type = 'block';
$pane->subtype = 'user-2';
$pane->access = array();
$pane->configuration = array (
'override_title' => 0,
'override_title_text' => '',
'css_id' => '',
'css_class' => '',
'module' => 'user',
'delta' => '2',
'block_visibility' => 0,
'block_settings' =>
array (
'user_block_whois_new_count' => '5',
),
);
$display->content['new-3'] = $pane;
$display->panels['row_1_2'][0] = 'new-3';
$pane = new stdClass();
$pane->pid = 'new-4';
$pane->panel = 'row_1_2';
$pane->type = 'block';
$pane->subtype = 'user-3';
$pane->access = array();
$pane->configuration = array (
'override_title' => 0,
'override_title_text' => '',
'css_id' => '',
'css_class' => '',
'module' => 'user',
'delta' => '3',
'block_visibility' => 0,
'block_settings' =>
array (
'user_block_seconds_online' => '900',
'user_block_max_list_count' => '10',
),
);
$display->content['new-4'] = $pane;
$display->panels['row_1_2'][1] = 'new-4';
$pane = new stdClass();
$pane->pid = 'new-5';
$pane->panel = 'row_1_2';
$pane->type = 'views';
$pane->subtype = 'archive';
$pane->access = array();
$pane->configuration = array (
'context' =>
array (
0 => 'empty',
),
'override_title' => 0,
'override_title_text' => '',
'css_id' => '',
'css_class' => '',
'view' => 'archive',
'type' => 'embed',
'link_to_view' => 1,
'more_link' => 0,
'feed_icons' => 0,
'use_pager' => 0,
'pager_id' => 1,
'nodes_per_page' => '10',
'offset' => '',
'panel_args' => 0,
'args' => '',
'url' => '',
);
$display->content['new-5'] = $pane;
$display->panels['row_1_2'][2] = 'new-5';
$pane = new stdClass();
$pane->pid = 'new-6';
$pane->panel = 'row_1_2';
$pane->type = 'block';
$pane->subtype = 'comment-0';
$pane->access = array();
$pane->configuration = array (
'override_title' => 0,
'override_title_text' => '',
'css_id' => '',
'css_class' => '',
'module' => 'comment',
'delta' => '0',
'block_visibility' => 0,
);
$display->content['new-6'] = $pane;
$display->panels['row_1_2'][3] = 'new-6';
$page->display = $display;
$page->displays = array();
I followed this and had problems....
Step 29 I believe is misleading. I could not find any views for the frontpage. I did follow the steps carefully.
I changed the frontpage to add 'block' type and that showed up. I realised that Panels 2 during setup states that there is a Legacy Views module. The comment states not to add it for new installs so I didn't. So I could not add the frontpage view. I then found that the new interface you have to add a view through Panels Views and then the front page will show up!
I still can't get it to work...
I worked through all the above, and the frontpage view is still not listed when I try adding content to the panel. I appreciate the need to create a frontpage view through Panels Views first, but still made no difference. Grrr!
On a test install, I enabled the Legacy Views module just to see... and it worked! I really don't want to do this on live install though, as the comment advises against it.
When you added the view in Panels Views, did you select block, page or embedded view type? I think I've tried them all.
I've had a support request open on this for a while...
Here is how I solved that issue
First follow everything through as described; however, before you move onto configuring your new panel page, go into panel view.
Once you are in there you should be able to see a drop down list of different views, and you should see the 2 views you created earlier in the exercise. Select the first one (frontpage) and add it and don't make any change and just save it, then do the same with archive and save that.
Once that is done, start going into building up your panel; however, before you go to the content part, make sure you stop by context tab, click add Node ID and you can select what kind of content you want to enable in there as well but you wont see the view but that is ok.
Now save and then go to content and follow along. Hmmm, you might be able to tell that I am writing this as I am going through it and here is the next stick in your wheel.
Where it says to link title to view, and add the more feature, well, you have to do that in the panel view setting for those views (took me a minute to figure that out) once you have done that, jump over to the panel page again and follow along.
Well, it almost worked; the only thing that doesn't work for me is to get the frontpage view to display, however, all of my other items does display. If anyone figures out what the problem is or get it to work let me know.
I just needed one more minute, shortly after posting this I figured out what was wrong with my view; if you have the same problem with the frontpage view not displaying, then jump over to panel view, select your front page view that you added earlier and in the argument drop down box, set it to no argument since the arguments are coming from the view it self which is defined in the view configuration.
That's it, I'm taking an hour off now without thinking about this any more so this is my last update to this post for now.....minute went by and I didn't figure out anything else so it's safe to post the article. :)
/Chris W.
Getting front page to display the newly created panel on tutoria
Chris,
I also thought I made a mistake but then found out that it worked clicking on my logo but not on my created "Home" link. in primary links menu..
I created this home link as http://yourdomain.net/node but the new link should be http://yourdomain.net/front or it worked also when i used http://yourdomain.net/
Hope this helps
Enable "Legacy views panes"
Enable "Legacy views panes" module in your modules page and views will show.
I can´t add content
Hi, on the step 29 when I Click the plus sign on the left, this doesn´t work.