1

I created a template for my view (views-view-fields-xxx.tpl.php). On my view page I use the 'Views Data Export Module' to export filtered views in XLS format.

I cannot figure out how to display the button on the top of the page. I tried printing it out in my template file using :

<?php print $view->feed_icon ?>

but then it prints out the button on every field view. Is there a way to print this field only once? Or another way to move the "feed-icon" to the top of my page?

2 Answers 2

3

Solution from: https://www.drupal.org/node/2117433#comment-9422881

  1. Copy the views-view.tpl.php file from views into your theme (or its templates directory if it has one). Note that you can rename the file in certain ways to make it specific to an individual view or display. The "Theme: Information" section of the views UI will give you more information. Also see the blog post for more information on that.
  2. Clear the cache so the site starts using your new template file instead of the default views one. The "Theme: Information" part of the views UI should now indicate that your file is being used.
  3. In your theme's version of the template file move the feed icon section wherever you want it. Potentially you would put it under the exposed filters or something. Currently the the feed icon part of the template looks like this (move this whole section):

<?php if ($feed_icon): ?> <div class="feed-icon"> <?php print $feed_icon; ?> </div> <?php endif; ?>

2
  • Thanks @Jhilke. I've got one question. Why does it work in my 'views-view.tpl.php' template, but not in my 'views-view-fields--xxx.tpl.php' template? May 5, 2015 at 5:43
  • template files are bit tricky sometimes. you just need to try with different combinations... there is a documentation about how to use it, in drupal.org I guess...
    – user12947
    May 6, 2015 at 22:02
2

Another alternative (if you can't override the views-view.html.twig) would be to use a preprocess function:

// mysite.module

/**
 * Implements hook_preprocess_views_view().
 */
function mysite_preprocess_views_view(array &$variables) {
  // Move feed icon to the top of the result, instead of buttom.
  if (isset($variables['feed_icons'])) {
    $variables['attachment_before'] = array_merge($variables['attachment_before'], $variables['feed_icons']);
    unset($variables['feed_icons']);
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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