[DOCS][Dev] Add Templates

This commit is contained in:
Diogo Peralta Cordeiro 2021-08-01 16:47:54 +01:00
parent df1f12470f
commit 263a5f67f3
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
Templates
=========
GNU social uses the [Twig template engine](https://twig.symfony.com/).
When you handle a UI-related event, you add your own twig snippets either with
`App\Util\Formatting::twigRenderFile` or `App\Util\Formatting::twigRenderString`.
Example
-------
```php
public function onAppendRightPanelBlock(array $vars, array &$res): bool
{
if ($vars['path'] == 'attachment_show') {
$related_notes = DB::dql('select n from attachment_to_note an ' .
'join note n with n.id = an.note_id ' .
'where an.attachment_id = :attachment_id', ['attachment_id' => $vars['vars']['attachment_id']]);
$related_tags = DB::dql('select distinct t.tag ' .
'from attachment_to_note an join note_tag t with an.note_id = t.note_id ' .
'where an.attachment_id = :attachment_id', ['attachment_id' => $vars['vars']['attachment_id']]);
$res[] = Formatting::twigRenderFile('attachmentShowRelated/attachmentRelatedNotes.html.twig', ['related_notes' => $related_notes]);
$res[] = Formatting::twigRenderFile('attachmentShowRelated/attachmentRelatedTags.html.twig', ['related_tags' => $related_tags]);
}
return Event::next;
}
```
Regarding using the Twig language, you can refer to
[Twig Documentation](https://twig.symfony.com/doc/3.x/templates.html).