1

I am using the Group: Combine fields filter (grouped) in Views and I want to separate my first few list items from the last two with a header before the last two. Is it possible without theme functions, like with some field in Views I do not know about?

Found these similar, but they use theme functions.

Add additional element to exposed view form? https://www.drupal.org/node/893392

0

Not that I know of without a theme function or a view display template. However one option without any code would be to create two separate blocks views.

The first view, limit the displayed items to whatever your want, three for example. Clone the first view, but set the offset to three, and also limit it. Add the header to this view. Then plunk them down as you normally would with view blocks.

EDIT: What it would like like to add a new template file.

As an example, if you are using the unformatted list output, you would need to find the theme suggestion for that particular view. Example below.

Example Theme Suggestions

Then as you can see it is currently using views-view-unformatted.tpl.php

So use that file as a base, it is located in:sites/<all|default|siteurl>/modules/views/theme/views-view-unformatted.tpl.php

It currently contains this code below

<?php

/**
 * @file
 * Default simple view template to display a list of rows.
 *
 * @ingroup views_templates
 */
?>
<?php if (!empty($title)): ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
  <div<?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"';  } ?>>
    <?php print $row; ?>
  </div>
<?php endforeach; ?>

So you need to copy this file into your theme templates folder, rename it, and edit it.

You're going to want to create a count variable, and then when the count reaches the right number, print the title you want like so

<?php

/**
 * @file
 * Default simple view template to display a list of rows.
 *
 * @ingroup views_templates
 */
?>
<?php if (!empty($title)): ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>
<?php $count = 1; ?>
<?php foreach ($rows as $id => $row): ?>
  <?php if ($count == 3) print "<h1>" . t('Header') . "</h1>"; ?>
  <div<?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"';  } ?>>
    <?php print $row; ?>
  </div>
  <?php $count++; ?>
<?php endforeach; ?>

That will print a H1 header after the third row.

  • Thanks, I thought of that, but would the two set of inputs still be able to work together? Like show results when there is a match for box 1 in the first block AND also for box 3 in the second block? – jcharlesberry Jun 23 '15 at 19:33
  • @jcharlesberry I really feel like your best option here is to modify the template file, it would be the most simple and flexible solution. – VanD Jun 23 '15 at 21:42
  • Thanks for getting back to me and you brought some code! I copied that template into the theme folder, but is it supposed to show as an option under "Format" in Views? It's not there and I tried various file names. Thanks in advance. – jcharlesberry Jun 23 '15 at 22:30
  • Oh NM. I found out I had to use the machine name of the view. Thanks so much. Great learning experience! – jcharlesberry Jun 23 '15 at 23:08
  • Actually this has turned out to be a bit more complicated. The view in question is using better exposed filters and it is the filter list that needs the headline inserted. Is this even possible? – jcharlesberry Jun 23 '15 at 23:16

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.