Hi, not sure if this the *best* way to do this, but here is a solution Im working on. Most of this uses the base CSS provided by Bootstrap, but you might need to tweak it to custom to your requirements.
Scenario: fetch a set of page banners/images, page headings and links and output them to a Twitter Bootstrap 3 carousel on the home page.
Extensions / Modules:
getResources
pthumb
Bootstrap
1) Template Variables: create a template variable called: bannerImage and set its input to 'Image'. Associate this TV with the appropriate templates, and from the pages, upload a banner image for each page.
2) Then create a chunk that contains the outer elements of your carousel (I call this carouselOuter) - place [[$carouselOuter]] in the template / place you want the carousel to appear.
<div id="myCarousel" class="carousel slide" data-ride="carousel">
[[$carouselCountOuter]]
<div class="carousel-inner">
[[!getResources? &parents=`2` &tpl=`carouselItem` &limit=`100` &sortdir=`ASC` &includeTVs=`1` &processTVs=`1` &sortby=`menuindex` &depth=`0`]]
</div>
<a class="left carousel-control" href="#myCarousel" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a>
<a class="right carousel-control" href="#myCarousel" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
</div>
3) Notice the chunk called
CarouselCountOuter - that is the outer container for the dotted navigation bar. If you dont want to see the dotted navigation, leave this out.
Also, in this example, getResources is pulling all the child parents under the resource with an ID of '2' - change this to whatever resource you wish to target).
4) Next create a chunk called
carouselItem - this will be called in getResources call and will fetch each carousel slide:
<div class="item [[+idx:eq=`1`:then=`active`:else=``]]">
<a href="[[~[[+id]]]]">
<img class="img-responsive" src="[[+tv.carouselImage:pthumb=`w=1180&h=300&zc=c`]]" alt="[[+pagetitle]]" />
<div class="carousel-caption">
<h3>[[+pagetitle]]</h3>
</div>
</a>
</div>
(Note here [[+idx]] is used target the first resource and apply the class 'active' to it - this is removed and added dynamically by Bootstrap scripting to the current visible slide). pthub is used to crop-zoom and render the image at a certain width and height. Change these settings to your needs - see pthumb / phpthumbof in the modx help docs for ore info)
5) To display the navigation dots, create a chunk called
carouselCountOuter:
<ol class="carousel-indicators">
[[!getResources? &parents=`2` &tpl=`carouselCountInner` &limit=`100` &sortdir=`ASC` &sortby=`menuindex` &depth=`0`]]
</ol>
6) ...and then finally to display a list and count / fetch a navigation marker 'dot' for each carousel - create a chunk called
carouselCountInner:
<li data-target="#myCarousel" data-slide-to="[[+idx:decr]]" [[+idx:eq=`1`:then=`class="active"`:else=``]]></li>
(Note again, this is where [[+idx]] comes to the rescue - the carousel knows which slide to target by using [[+idx]]
with the decrement filter because the first slide starts on '0' whereas the [[+idx]] starts at 1 - in otherwords the 'data' resource starts at 0 -the modx resource starts at 1).
Im not absolutely sure if this is the best way of doing this - any input or feedback gratefully received.
Dan.