# Twig

Pour faciliter la création de templates, on peut utiliser le moteur de template Twig.

## Utilisation

```php
use ToosmarWireframe\Services\Twig;

$twig = new Twig();

// your template in `v2017b/5_specific_template/TOOSMART_WIREFRAME/templates`
$templatePath = 'pdf/construction-form/type-1.html.twig';

$htmlOfPdf = $twig->render($templatePath, [
    'interventionReport' => $interventionReportToTwig,
]);
```

## Service

Le service `Twig` est disponible dans l'espace de nom global `ToosmarWireframe\Services\Twig`. C'est le fichier `v2017b/5_specific_template/TOOSMART_WIREFRAME/services/Twig.php` qui le définit.

## Templates

Les templates sont des fichiers `.html.twig` qui sont stockés dans le dossier `v2017b/5_specific_template/TOOSMART_WIREFRAME/templates/`.

## Documentation générale de Twig

https://twig.symfony.com/

## Exemples

```php
use ToosmarWireframe\Services\Twig;

$twig = new Twig();

// your template in `v2017b/5_specific_template/TOOSMART_WIREFRAME/templates`
$templatePath = 'pdf/construction-form/type-1.html.twig';

$htmlOfPdf = $twig->render($templatePath, [
    'interventionReport' => $interventionReportToTwig,
]);
```

Avec le template suivant :

```twig
<!DOCTYPE html>
<head>
    <title>Formulaire de construction</title>
</head>
<body>
    <h1>Formulaire de construction</h1>
    <p>Intervention Report ID: {{ interventionReport.id }}</p>
    <p>Type: {{ interventionReport.type }}</p>
    <p>Date: {{ interventionReport.date|date('Y-m-d') }}</p>
    {% if interventionReport.att9 is defined %}
        <p>Att9: {{ interventionReport.att9 }}</p>
    {% endif %}
    {% for item in interventionReport.items %}
        <div>
            <h2>{{ item.name }}</h2>
            <p>Description: {{ item.description }}</p>
            <p>Quantity: {{ item.quantity }}</p>
        </div>
    {% endfor %}
</body>
</html>
```
