2017 © Pedro Peláez
 

library bem-twig-extension

Twig function that inserts static classes in BEM methodology.

image

chris-ware/bem-twig-extension

Twig function that inserts static classes in BEM methodology.

  • Tuesday, January 2, 2018
  • by chrisware
  • Repository
  • 1 Watchers
  • 0 Stars
  • 172 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 341 % Grown

The README.md

bem-twig-extension

Twig function that inserts static classes in BEM methodology., (*1)

Based on [https://github.com/drupal-pattern-lab/bem-twig-extension], but adapted to be available as a normal twig extension, (*2)

Add Extension

$twig = new Twig_Environment($loader, $options);
$twig->addExtension(new Bem\Twig\BemExtension());

Usage (4 arguments)

Simple block name (required argument):

<h1 {{ bem('title') }}>, (*3)

This creates:, (*4)

<h1 class="title">, (*5)

Block with modifiers (optional array allowing multiple modifiers):

<h1 {{ bem('title', ['small', 'red']) }}>, (*6)

This creates:, (*7)

<h1 class="title title--small title--red">, (*8)

Element with modifiers and blockname (optional):

<h1 {{ bem('title', ['small', 'red'], 'card') }}>, (*9)

This creates:, (*10)

<h1 class="card__title card__title--small card__title--red">, (*11)

Element with blockname, but no modifiers (optional):

<h1 {{ bem('title', '', 'card') }}>, (*12)

This creates:, (*13)

<h1 class="card__title">, (*14)

Element with modifiers, blockname and extra classes (optional - in case you need non-BEM classes):

<h1 {{ bem('title', ['small', 'red'], 'card', ['js-click', 'something-else']) }}>, (*15)

This creates:, (*16)

<h1 class="card__title card__title--small card__title--red js-click something-else">, (*17)

Element with extra classes only (optional):

<h1 {{ bem('title', '', '', ['js-click']) }}>, (*18)

This creates:, (*19)

<h1 class="title js-click">, (*20)

The Versions

02/01 2018

dev-master

9999999-dev https://github.com/chris-ware/bem-twig-extension#README

Twig function that inserts static classes in BEM methodology.

  Sources   Download

MIT

The Requires

 

by Chris Ware