Twitter Bootstrap Carousel with only one views template file

Public

Create a view titled "banners". Add the nodes you want included. Create a file with the following title and add the below code to it. views-view-unformatted--banners--default.tpl.php.

Obviously you may want to have a node with just images and links or whatever but this will implement the carousel with just this file.

Get raw version
php
  1. <?php
  2.  
  3. /**
  4.  * @file
  5.  * Default simple view template to display a list of rows.
  6.  *
  7.  * @ingroup views_templates
  8.  */
  9.  
  10.  
  11. ?>
  12. <?php if (!empty($title)): ?>
  13. <h3><?php print $title; ?></h3>
  14. <?php endif; ?>
  15. <div id="carousel-banner" class="carousel slide" data-ride="carousel">
  16. <!-- Indicators -->
  17. <ol class="carousel-indicators">
  18. <?php foreach ($rows as $id => $row) { ?>
  19. <?php if($id == 0) { $active = 'active'; } else { $active = ''; } ; ?>
  20. <li data-target="#carousel-banner" data-slide-to="<?php print $id; ?>" class="<?php print $active; ?>"></li>
  21. <?php } ?>
  22. </ol>
  23. <!-- Wrapper for slides -->
  24. <div class="carousel-inner" role="listbox">
  25. <?php foreach ($rows as $id => $row) { ?>
  26. <?php if($id == 0) { $active = 'active'; } else { $active = ''; } ; ?>
  27. <div class="item <?php print $active; ?>">
  28. <div<?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"'; } ?>>
  29. <?php print $row; ?>
  30. </div>
  31. </div>
  32. <?php } ?>
  33. </div>