openeuropa/ecl-twig-loader

Europa Component Library Twig loader.

2.1.0 2021-01-25 09:44 UTC

README

Build Status Packagist

Twig loader for Europa Component Library Twig implementation (ECL Twig), it allows to load components by accessing them via a configurable namespace.

For example, given you have the following ECL twig components:

/path/to/components/
├── ec-component-link
│   └── ecl-link.html.twig
└── ec-component-language-list
    ├── ecl-language-list.html.twig
    ├── ecl-language-list-item.html.twig
    ├── ecl-language-list-overlay.html.twig
    └── ecl-language-list-splash.html.twig

If you setup the loader as follows:

<?php

use \OpenEuropa\Twig\Loader\EuropaComponentLibraryLoader;

$loader = new EuropaComponentLibraryLoader(['ecl-twig'], '/components', '/path/to');
$twig = new Twig_Environment($loader);

Then you can load the link component in the following way:

{% include '@ecl-twig/ec-component-link/ecl-link.html.twig' with {
  link: { 
    type: 'standalone',
    label: 'Standalone link',
    path: 'http://google.com',
    icon_position: 'after'
  }
} %}

You can also use a shorter form, based on implicit naming conventions:

{% include '@ecl-twig/link' with {
  link: {
    type: 'standalone',
    label: 'Standalone link',
    path: 'http://google.com',
    icon_position: 'after'
  }
} %}

To load sub-components append them after the component name:

{% include '@ecl-twig/language-list/language-list-splash' %}

Installation using Docker Compose

The setup procedure can be simplified by using Docker Compose.

Requirements:

Copy docker-compose.yml.dist into docker-compose.yml.

You can make any alterations you need for your local Docker setup. However, the defaults should be enough to set the project up.

Run:

$ docker-compose up -d

Then:

$ docker-compose exec web composer install

Step debugging

To enable step debugging from the command line, pass the XDEBUG_SESSION environment variable with any value to the container:

docker-compose exec -e XDEBUG_SESSION=1 web <your command>

Please note that, starting from XDebug 3, a connection error message will be outputted in the console if the variable is set but your client is not listening for debugging connections. The error message will cause false negatives for PHPUnit tests.

To initiate step debugging from the browser, set the correct cookie using a browser extension or a bookmarklet like the ones generated at https://www.jetbrains.com/phpstorm/marklets/.