2017 © Pedro Peláez
 

laravel-package bauhausblock

Simple block handling for laravel

image

krafthaus/bauhausblock

Simple block handling for laravel

  • Tuesday, September 2, 2014
  • by jspekken
  • Repository
  • 1 Watchers
  • 0 Stars
  • 20 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Bauhaus Block - Rendering of block elements

Latest Stable Version Latest Unstable Version Total Downloads License, (*1)

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)

Installation

Add bauhaus block to your composer.json file:, (*3)

"require": {
    "krafthaus/bauhausblock": "dev-master"
}

Use composer to install this package, (*4)

$ composer update

Register the package

'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)

Your first block

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)

Support

Have a bug? Please create an issue here on GitHub that conforms with necolas's guidelines., (*12)

License

This package is available under the MIT license., (*13)

The Versions

02/09 2014

dev-master

9999999-dev

Simple block handling for laravel

  Sources   Download

MIT

The Requires

 

by KraftHaus

laravel cms backend views blocks bauhaus admin generator