dev-master
9999999-devSimple block handling for laravel
MIT
The Requires
- php >=5.4.0
- illuminate/support 4.2.*
by KraftHaus
laravel cms backend views blocks bauhaus admin generator
Simple block handling for laravel
Handle rendering of block element. A block is a small unit with its own logic and templates. A block can be inserted anywhere in a current laravel template., (*2)
Add bauhaus block to your composer.json file:, (*3)
"require": { "krafthaus/bauhausblock": "dev-master" }
Use composer to install this package, (*4)
$ composer update
'providers' => array( 'KraftHaus\BauhausBlock\BauhausBlockServiceProvider' ), 'aliases' => array( 'Block' => 'KraftHaus\BauhausBlock\Facades\Block' )
Add the blocks
folder to the app/
directory and put the following line in your composer.json file:, (*5)
"autoload": { "classmap": [ "app/blocks" ] }
Then run $ composer dump-autoload
and you're done., (*6)
This quick tutorial explains how to create a RSS reader block. A block is nothing more than a class defining properties that renders a block partial., (*7)
Every block you create for your project should be located in the app/blocks
folder. So lets create an RssBlock.php
file in that folder with the following contents:, (*8)
<?php use KraftHaus\BauhausBlock\Block; use KraftHaus\BauhausBlock\Resolver\OptionResolver; class RssBlock extends Block { /** * Configure the block with this method. * Use the OptionResolver instance to set or get options for this block. */ public function configure(OptionResolver $resolver) { $resolver ->set('url', 'https://github.com/krafthaus/bauhaus/commits/master.atom') ->set('view', 'blocks.rss'); } /** * This method is called every time a block is rendered and used to * initialize the block with data. */ public function execute() { $options = $this->getOptionResolver(); $content = file_get_contents($options->get('url')); $feed = simplexml_load_string($content); $options->set('feed', $feed->entry); return $this; } }
Create the view for this block at app/views/blocks/rss.blade.php
with the following contents:, (*9)
<ul> @foreach ($options->feed as $item) <li>{{ $item->title }}</li> @endforeach </ul>
To render the block just call:, (*10)
{{ Block::render('rss') }}
That's it!, (*11)
Have a bug? Please create an issue here on GitHub that conforms with necolas's guidelines., (*12)
This package is available under the MIT license., (*13)
Simple block handling for laravel
MIT
laravel cms backend views blocks bauhaus admin generator