This symfony bundle provides BEM helper functions to use in twig template.
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Open a command console, enter your project directory and execute:
$ composer require mothership/twig-bem-bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require mothership/twig-bem-bundle
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php
file of your project:
// config/bundles.php
return [
// ...
Mothership\TwigBemBundle\TwigBemBundle::class => ['all' => true],
];
Use it like this: <div class="{{ bemBlock('myBlock') }}"></div>
Parameters:
- blockName: String
- modifiers: (optional) String[]
This function can only be used if there is a bemBlock
defined in the parent tree.
Use it like this: <div class="{{ bemElem('myElement') }}"></div>
Parameters:
- elementName: String
- modifiers: (optional) String[]
{% block body %}
<div class="{{ bemBlock('listing') }}">
<div class="{{ bemElem('pagination') }}"></div>
<div class="{{ bemBlock('product') }}">
<div class="{{ bemElem('title') }}"></div>
</div>
<div class="{{ bemBlock('product', ['active', 'sale']) }}">
<div class="{{ bemElem('title', ['bold']) }}"></div>
</div>
</div>
{% endblock %}
This will be the corresponding output/markup:
<div class="listing">
<div class="listing__pagination"></div>
<div class="product">
<div class="product__title"></div>
</div>
<div class="product product--active product--sale">
<div class="product__title product__title--bold"></div>
</div>
</div>