PHPackages                             aklump/bem - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. aklump/bem

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

aklump/bem
==========

A PHP project to enforce the Block Element Modifier (CSS) methodology.

0.0.5(3w ago)072BSD-3-ClausePHPPHP &gt;=7.3

Since Nov 26Pushed 3w ago1 watchersCompare

[ Source](https://github.com/aklump/bem)[ Packagist](https://packagist.org/packages/aklump/bem)[ Docs](https://github.com/aklump/bem)[ RSS](/packages/aklump-bem/feed)WikiDiscussions main Synced 2w ago

READMEChangelogDependencies (6)Versions (6)Used By (0)

BEM
===

[](#bem)

BEM — is a methodology that helps you to create reusable components and code sharing in front‑end development

Usage
-----

[](#usage)

Create a class instance to represent your BEM model. Pass the "block" as the constructor argument.

```
$bem = new \AKlump\Bem\Fluent\Bem('foo');
```

All methods return an object instance that can be typecast to a string. Or, you can also call `toString()` or `toArray()` as appropriate; see `\AKlump\Bem\Fluent\Interfaces\OutputInterface` for details. All of the following produce the same output.

```
(string) $bem->block(); // foo
strval($bem->block()); // foo
$bem->block()->toString(); // foo

```

For simplicity any remaining examples will show only the first form.

### The Basic Four

[](#the-basic-four)

```
(string) $bem->block(); // "foo"
(string) $bem->element('content'); // "foo__content"
(string) $bem->block()->modifier('has-image'); // "foo--has-image"
(string) $bem->element()->modifier('content', 'has-image'); // "foo__content--has-image"
```

### For Javascript Purposes

[](#for-javascript-purposes)

```
(string) $bem->block()->js(); // "js-foo"
(string) $bem->element('content')->js(); // "js-foo__content"
```

### String Cast Gotcha

[](#string-cast-gotcha)

If you lean on the automatic string casting you may get into trouble in the following situation. In the incorrect code, you end up with `lorem__content` for both classes; the correct way to handle this situation is to explicitly cast to string.

```
