Repeaters

Usage

{!! PageBuilder::block($block_name, $options) !!}

ie. {!! PageBuilder::block('banners', ['view' => 'home_banners']) !!}

Method Options ($options)

'view' => 'home_banners' (default: is the block_name)

'random' => 2 (default: off, can set to pull back a number of randomly selected repeater rows in a random order)

'per_page' => 5 (default: off, can add pagination if there are lots of rows)

'cols' => '6'   (default: 1, can set to 2 to pull back odd and even rows)

'column' => '5'   (default: 1, if above is set to 2, then 1 will pull back odd rows and 2 even)

Template Locations

/blocks/repeaters/[repeater_view].blade.php

repeater view is the block name unless set otherwise by the view variable

Avaliable Variables

$id (int - repeaters id)

$is_first (bool - check if first repeater row)

$is_last (bool - check if last repeater row)

$count (int - gets total number of repeater rows)

$total (int - total number of repeater rows)

$pagination or $links (string - returns the pagination links)

Examples

The banners block is completely optional and is a good example of Coaster's repeater functionality. 

@if ($is_first)
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators">
        @for ($i = 0; $i < $total; $i++)
        <li data-target="#carousel-example-generic" data-slide-to="{!! $i !!}"{!! ($i==0)?' class="active"':'' !!}></li>
        @endfor
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner dupa">
@endif

        <div class="item {!! ($count==1)?'active':'' !!} car{!! $count !!}">
            <div class="carousel-caption">
                <h1>{!! PageBuilder::block('slide_title') !!}</h1>
                <a href="{!! PageBuilder::block('slide_link') !!}" class="btn btn-primary" >Find out more</a>
            </div>
        </div>

@if ($is_last)
    </div>

    <!-- Controls -->
    <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
        <span class="glyphicon glyphicon-chevron-left"></span>
    </a>
    <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
        <span class="glyphicon glyphicon-chevron-right"></span>
    </a>
</div>
@endif

The first part of this view is composed between the $is_first conditional statement. The code in this statement will be executed once, this is often done to prevent the whole section from repeating itself with eache banner. The $is_last conditional does much the same thing but often for the closing elements of the section such as the div tags. Anything between these two conditions will render for each repeating element. In this case the number of banners. This is essentially the Coaster equivalent to a foreach loop in classic PHP. To get the number assigned to each banner the $count variable can be used, this is very much like the conventional $i variable used in many PHP loops.

Repeater Forms

In Coaster 5.3, we introduced a feature for creating forms for frontend users to submit content to repeaters (like the comments form in the Coaster206 theme).

To do this, first create a repeater block. Then create a file in views/themes[theme]/blocks/repeaters/[block_name]-form.blade.php and create a form with the fields from your repeater block for users to submit their form to the repeater. The (coaster 2016) theme comments repeater block uses this feature - so that's a good place to start when trying this out.

Modern Framework

Based on Laravel 5

Constant development

Additional features always being planned/researched

Open source

"git" involved

Latest from the blog


read more


read more


read more