1

I'm sure this isn't difficult, but I can't seem to figure it out. I have about 10 block displays generated from one view that needs a single html wrap (Setting the css property in the view itself is not what I'm looking for). Devel themer module is suggesting block--views.tpl.php, however that obviously affects all blocks generated by views. I assume a preprocess function would be best. The function below works, but I need to target a specific view.

Thanks in advance.

  function mytheme_preprocess_block(&$variables) {
    if ($variables['block']->module == 'views') {
      $variables['classes_array'][] = drupal_html_class('semester-container');
    }
  }
1

The answer suggested by madhurjya is correct, but I would point out that it is possible to create a template that is applied to all block displays of a certain view. E.g. for a view Blog with Unformatted type of output you can use views-view-unformatted--blog--block.tpl.php to alter all blocks only from that view.

Explore the Theme:Information in the Advanced settings of a view to see all your options.

  • Thanks, but I'm trying to encapsulate each block with same tag, this includes the block title. The template file you suggested only effects the inner content of the block, which I'm currently using as well. Maybe I'm not utilizing the template file properly? – knice Jun 26 '14 at 15:51
1

Thanks, but I was able to figure it out using the preprocess_block function.

  function mytheme_preprocess_block(&$variables) {
    kpr($variables); //Find a common element then add to the conditional below
    if ($variables['block']->module == 'views' && $variables['block']->context == 'curriculum_semester_breakouts') {
      $variables['classes_array'][] = drupal_html_class('semester-container');
    }
  }
0

Use function hook_views_pre_render to customize the html, or u can use the view theme templates which u will get for each view block display by clicking on advance tab of view configuration page and for documentation on views template you can read this link.hope this will help u.

Following is one of my view, array of $view, Here you can see under the display, i have total five display between that i have two blocks block_1 & block_2 each block has its id as unique so you can modify ur code based on this $view->display['block_1']->id so on.... Hope this will. help you.

enter image description here

  • How would I break the result to target each block? – knice Jun 26 '14 at 16:21
  • codeshare.io/aYb9z – knice Jun 26 '14 at 16:27
  • see my edit on my answer. – madhurjya Jun 27 '14 at 5:03
  • Thank you Madhurjya. Since I have over 10 blocks displaying at once, can't I target all blocks in a particular view rather than calling each by their machine name? – knice Jun 30 '14 at 2:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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