2017 © Pedro PelĂĄez
 

library bem-php

PHP shortcodes to generate BEM class with a Laravel integration

image

kagagnon/bem-php

PHP shortcodes to generate BEM class with a Laravel integration

  • Monday, July 9, 2018
  • by kagagnon
  • Repository
  • 1 Watchers
  • 0 Stars
  • 134 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 68 % Grown

The README.md

Installation

Install via composer with, (*1)

$ composer install kagagnon/bem-php

Optional configurations

Configurations are static properties to the KAGagnon\BemPhp\Helpers\BemHelper class. You can edit them before using BemPhp:, (*2)

 $has_sugar == true
] );
```

You can mix conditional modifiers with other modifiers, and it also works with the `startBlock` method.

```php
BemHelper::startBlock( 'cup', 'div', [
    '_modifiers' => [
        'blue',
        'is-cold' => !$has_hot_beverage,
        'is-empty' => $finished
    ]
] );
```


## HTML example

```php



Article Name

Article text..., (*3)

Result to :, (*4)



Article Name

Article text..., (*5)

Create node with startBlock()

You can pass argument to startBlock() to automatically generate an HTML tag. To do so, you can pass the tag name as second argument and, optionally, an array of attributes., (*6)

You can also skip the tag name and pass an array as second argument. That will create an HTML element base on the default_tag configuration., (*7)

Additionally, if you set create_tag to true, startBlock() will always create a tag base on the default_tag configuration if only 1 argument is passed., (*8)

To pass modifiers to the tag, simply pass _modifiers in the array: an array for multi-modifiers or a string for single modifier., (*9)

Example

<?php
// We assume `create_tag` is set to true

BemHelper::startBlock( 'block' ) // 

BemHelper::endBlock() //
BemHelper::startBlock( 'block', 'article' ) // <article class="block"> BemHelper::endBlock() // </article> BemHelper::startBlock( 'block', 'quote', [ 'data-inspiration', 'class' => 'js-action' ] ) // <quote class="js-action block" data-inspiration > BemHelper::endBlock() //</quote> BemHelper::startBlock( 'block', [ 'id' => "anchor" ] ) //
BemHelper::endBlock() //
BemHelper::startBlock( 'block', [ 'id' => "anchor", '_modifiers' => 'modifier' ] ) //
BemHelper::endBlock() //
BemHelper::startBlock( 'block', [ '_modifiers' => [ 'modifier1', 'modifier2' ] ] ) //
BemHelper::endBlock() //

Use with Laravel (Blade directives)

This plugin comes with a Laravel integration. You can include the KAGagnon\BemPhp\BemServiceProvider class in your application service providers list. The following directive will be mapped :, (*10)

@bem( ... ) => BemHelper::startBlock
@bemclass( ... ) => BemHelper::bemClass
@endbem => BemHelper::endBlock

Twig extension

This plugin comes with a Twig integration. You can register the KAGagnon\BemPhp\Twig\BemTwigExtension in Twig extensions. The following directive will be mapped :, (*11)

{% bem( ... ) %} => BemHelper::startBlock
{{ bemclass( ... ) }} => BemHelper::endBlock
{% endbem %} => BemHelper::getBemClass

The Versions

09/07 2018

dev-master

9999999-dev

PHP shortcodes to generate BEM class with a Laravel integration

  Sources   Download

MIT

by Karl-André Gagnon

laravel php blade bem shortcode

09/07 2018

0.1.9

0.1.9.0

PHP shortcodes to generate BEM class with a Laravel integration

  Sources   Download

MIT

by Karl-André Gagnon

laravel php blade bem shortcode

04/07 2018

0.1.8

0.1.8.0

PHP shortcodes to generate BEM class with a Laravel integration

  Sources   Download

MIT

by Karl-André Gagnon

laravel php blade bem shortcode

08/06 2018

0.1.7

0.1.7.0

PHP shortcodes to generate BEM class with a Laravel integration

  Sources   Download

MIT

by Karl-André Gagnon

laravel php blade bem shortcode

06/04 2018

0.1.6

0.1.6.0

PHP shortcodes to generate BEM class with a Laravel integration

  Sources   Download

MIT

by Karl-André Gagnon

laravel php blade bem shortcode

06/02 2018

0.1.5

0.1.5.0

PHP shortcodes to generate BEM class with a Laravel integration

  Sources   Download

MIT

by Karl-André Gagnon

laravel php blade bem shortcode

29/01 2018

0.1.4

0.1.4.0

PHP shortcodes to generate BEM class with a Laravel integration

  Sources   Download

MIT

by Karl-André Gagnon

laravel php blade bem shortcode

20/06 2017

0.1.3

0.1.3.0

Blade shortcodes to generate BEM class

  Sources   Download

MIT

by Karl-André Gagnon

laravel blade bem shortcode

09/06 2017

0.1.2

0.1.2.0

Blade shortcodes to generate BEM class

  Sources   Download

MIT

by Karl-André Gagnon

laravel blade bem shortcode

04/05 2017

0.1.1

0.1.1.0

Blade shortcodes to generate BEM class

  Sources   Download

MIT

by Karl-André Gagnon

laravel blade bem shortcode

28/04 2017

0.1

0.1.0.0

Blade shortcodes to generate BEM class

  Sources   Download

MIT

by Karl-André Gagnon

laravel blade bem shortcode