heydon/blt-twig

Expands on robo-twig to add additional support for blt

Installs: 7 434

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

Type:robo-tasks

dev-master 2018-06-26 06:01 UTC

This package is auto-updated.

Last update: 2024-12-17 15:59:45 UTC


README

Twig is such a powerful templating language and the built in replace command in robo completely inadiquate. Tasks such as building a default settings.php for Drupal where you take many different variables from the blt config yaml file can very challenging.

$this->taskReplaceInFile('box/robo.txt')
 ->from(
 [
    '##dbname##',
    '##dbhost##'
 ])
 ->to(
 [
    $this->getConfigValue('drupal.db.database'),
    $this->getConfigValue('drupal.db.host')
 ])
 ->run();

Compared to twig

$this->taskTwig($this)
     ->setTemplatesDirectory($this->getConfigValue('repo.root') . '/blt/Templates')
     ->applyTemplate('settings.php.twig', $this->getConfigValue('drupal.settings_file'))
     ->applyTemplate('sites.php.twig', $this->getConfigValue('docroot') . '/sites')
     ->run();

Using the template which is provided.

$databases['default']['default'] = array (
  'database' => '{{ config.drupal.db.database }}',
  'username' => '{{ config.drupal.db.username }}',
  'password' => '{{ config.drupal.db.password }}',
  'prefix' => '',
  'host' => '{{ config.drupal.db.host }}',
  'port' => '{{ config.drupal.db.port }}',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

The task and config variables are automatically exposed during the ::twigTask(), so your templates have full access to every config variable while it is being generated.