Skip to content
/ widget Public
forked from pingpong-labs/widget

Simple widget system for create awesome feature on blade templating Laravel 4

License

Notifications You must be signed in to change notification settings

yaapis/widget

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Widget System - Laravel 4.*

Simple widget system for create awesome feature on blade templating Laravel 4

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Donation

If you find this source is useful, you can share some milk to me if you want ^_^

Donate

Installation

Open your composer.json file, and add the new required package.

  "pingpong/widget": "1.0.*" 

Next, open a terminal and run.

  composer update 

After the composer updated. Add new service provider in app/config/app.php.

  'Pingpong\Widget\WidgetServiceProvider'

Done.

Example

Registering your widget

To register your widget, simply create a file widgets.php in your app folder and put your widgets code in that file. Like this.

laravel/
|-- app/
	|-- commands/
	...
	|-- views/
	|-- filters.php
	|-- routes.php
	|-- widgets.php
|-- bootstrap/
|-- vendor/

Simple Widget :

Widget::register('awesome', function(){

	return View::make('awesome');

});

Widgets with one or more parameters:

Widget::register('hello', function($name){

	return "Hello, $name !";

});

Widget::register('box', function($title, $description){

	return View::make('widgets.box', compact('title', 'description'));

});

Widget grouping of widgets that have previously been defined.

// First, you must registering one or more widget

Widget::register('categories', function(){
	return View::make('widgets.categories');
});

Widget::register('latestPost', function(){
	return View::make('widgets.latestPost');
});

// Next, you can group some widgets like this:

Widget::group('sidebar', array('categories', 'latestPost'));

Widget::group('footer', array('hello', 'box'));

Calling your widget

Globally calling the widget just like below:

Widget::awesome();

Widget::hello('Jhon');

Widget::box('Latest News', 'This is a description of latest news');

// calling widget group just like below
// Widget::$name();
Widget::sidebar();

// calling widget group which parameters just like below
// Widget::$name($params1, $params2, $params3, ....);
Widget::box(array('name'), array('My Tweets', '.....Latest Tweets'));

simple calling widget on view :

@awesome

@hello('John')

//calling group widget

@sidebar()

@box(array('name'), array('My Tweets', '.....Latest Tweets'))

License

This package is open-sourced software licensed under the MIT license

About

Simple widget system for create awesome feature on blade templating Laravel 4

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%