Skip to content

Instantly share code, notes, and snippets.

@crynobone
Created March 7, 2013 09:55
Show Gist options
  • Select an option

  • Save crynobone/5106886 to your computer and use it in GitHub Desktop.

Select an option

Save crynobone/5106886 to your computer and use it in GitHub Desktop.
Simple Caroussel widget for Orchestra Platform.
<?php
class Caroussel extends Orchestra\Widget\Driver {
/**
* Type
*
* @access protected
* @var string
*/
protected $type = 'caroussel';
/**
* Configuration
*
* @access protected
* @var array
*/
protected $config = array(
'defaults' => array(
'image' => '',
'link' => '',
),
);
/**
* Add an item to current widget.
*
* @access public
* @param string $id
* @param mixed $location
* @param Closure $callback
* @return mixed
*/
public function add($id, $location = 'parent', $callback = null)
{
if ($location instanceof Closure)
{
$callback = $location;
$location = 'parent';
}
if (starts_with($location, 'child')) $location = 'parent';
$item = $this->nesty->add($id, $location ?: 'parent');
if ($callback instanceof Closure)
{
call_user_func($callback, $item);
}
return $item;
}
}
Orchestra\Widget::extend('caroussel', function ()
{
return new Caroussel;
});
$caroussel = Orchestra\Widget::make('caroussel.default');
$caroussel->add('slide1', function ($c)
{
$c->image('image1.jpg');
$c->link('http://path.com');
});
$caroussel->add('slide2', function ($c)
{
$c->image('image2.jpg');
$c->link('http://path.com');
});
// In your view
@foreach ($caroussel->get() as $slide)
<a href="{{ $slide->link }}"><img src="{{ $slide->image }}"></a>
@endforeach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment