Drupal Tips: How to create a custom view in Drupal 7
https://www.zyxware.com/sites/default/files/styles/user_image/public/pictures/zyxlogo.png?itok=J9t-ZEoU
BY webmaster
7 years ago
Web-Development
2 comments comment

By default Drupal 7 has two types of views - The Full node view and the Teaser view. This has been the case for all previous versions of Drupal. However if your requirements are different, then you might have to create a custom view that is tailored to meet your specific needs. Check out how to create a simple custom “View mode” for nodes in Drupal 7.

Step1: Create a custom module
Step2: Create an additional view mode -’Grid Pane’ by simply implementing hook_entity_info_alter() in our custom module.

/** 
* Implements hook_entity_info_alter().
*/
function CustomModule_entity_info_alter(&$entity_info) {
  $entity_info['node']['view modes']['grid_pane'] = array(
    'label' => t('Grid Pane'),
    'custom settings' => TRUE,
  );
}

Step3: Now apply some theme and custom layout for the content. We can add a custom node.tpl.php template for this view mode for flexible theming and use standard hook_preprocess_node() function to control the variables available in the template.
To make Drupal use a different .tpl.php file for view mode we need to add a new template suggestion in hook_preprocess_node (). Copy the standard node.tpl.php for the content type you need and name it like “node--article--grid_pane.tpl.php”.

/**
* Implements hook_preprocess_node().
*/
function CustomModule_preprocess_node(&$vars) {
  /*dpm(entity_get_info());*/
  if($vars['view_mode'] == 'grid_pane') {
    $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__grid_pane';
  }
}

Step4: Install the custom module and we are done. Once we create a new view mode, we can go to Admin->Structure->content types->[Manage Display] page and select which fields to display format and additional options for fields, like which image style to use for image fields etc. For example:

Drupal


RELATED ARTICLE

/themes/custom/zyxpro_light/images/placeholder.png
close

on 09th April 2007 / by webmaster
Freelance projects fall into a separate category of projects in that they target independent deve Community Projects Freelance Open Source Web Development Leave a reply Your email address will not be published. Required fields are marked * Shrinivasan (not verified) access_time 14 Dec 2019 - 17:05 Guys. Great Collection and a great site. It is really impressive to know that there a numerous FOSS tools for web contents. Thanks. Keep Growing. Anonymous (not verified) access_time 14 Dec 2019 - 17:05 In reply to Great collection by Shrinivasan (not verified) Great Collection and a great site!!! Thanks! Silvia (not verified) access_time 14 Dec 2019 - 17:05 Hi, nice work. I also love to use WordPress when setting up a new blog. Greetings JungleDirector (not verified) access_time 14 Dec 2019 - 17:05 Subj. Anybody have? I'ts better, if you have XRumer 5.04... Gimme link Thanks. Ingo (not verified) access_time 14 Dec 2019 - 17:05 Hi, this is a listing of open source software was looking for my new project Thx a lot Pagination Current page 1 Page 2 Page 3 Page 4 Page 5 Next page Next › Last page Last » Add new comment
Leave a reply
Your email address will not be published. Required fields are marked *

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type='1 A I'> <li> <dl> <dt> <dd> <h2 id='jump-*'> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
The content of this field is kept private and will not be shown publicly.
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

author-image
uk (not verified)
access_time 14 Dec 2019 - 20:51

Hi,

It would be good if you rename the preprocess function tdbcustom_preprocess_node to CustomModule_preprocess_node

Thanks,
UK.