Bonjour,
Mon tableau :
Me retourne, dans un fichier PDF, le tableau de ma facture :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 <table class="detailsTable"> <tr class="tableHeader"> <th class="tableDesignationColumn">{{ "orderTable.designation"|trans }}</th> <th class="tableVATColumn">{{ "orderTable.tva"|trans }}</th> <th class="tablePUColumn">{{ "orderTable.unitPrice"|trans }}</th> <th class="tableQteColumn">{{ "orderTable.quantity"|trans }}</th> <th class="tableAmountColumn">{{ "orderTable.total"|trans }}</th> </tr> {% for item in items %} <tr class="tableBody"> <td class="firstCell">{{ item.designation}}</td> <td class="align-right"> {% if item.tva is not null %} {{ item.tva }} {% endif %} </td> <td class="align-right">{{ item.unitPrice }}</td> <td class="align-right">{{ item.quantity }}</td> <td class="align-right">{{ item.total }}</td> </tr> {% endfor %} <tr class="firstTableFooter"> <td class="tableDeliveryFooter"> </td> <td class="tableHTFooter" colspan="3">{{ "orderTable.totalHT"|trans }}</td> <td class="align-right">{{ order.totalHt }}</td> </tr> {% for rate, total in vats %} <tr class="tableFooter"> <td></td> <td class="tableHTFooter" colspan="3">{{ "orderTable.totalVAT"|trans }} {{ rate }}</td> <td class="align-right">{{ total }}</td> </tr> {% endfor %} <tr class="tableFooter"> <td></td> <td class="tableHTFooter" colspan="3">{{ "orderTable.totalTTC"|trans }}</td> <td class="align-right">{{ order.totalTtc }}</td> </tr> </table>
Je désire réaliser, par exemple à l'aide d'une fonction Twig, afficher ou non certaines colonnes du tableau en mettant des paramètres à true ou false.
Pour l'instant, dans mon fichier "AppExtension", j'ai fait ceci :
Je récupère mon Order et les paramètres que je veux afficher dans mon tableau.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 namespace AppBundle\Twig; use AppBundle\Entity\Order; class AppExtension extends \Twig_Extension { public function getFilters() { return array( new \Twig_SimpleFilter('array_sum', 'array_sum'), ); } public function getFunctions() { return array( new \Twig_SimpleFunction('getInvoiceTable', [$this,'getInvoiceTable']), ); } public function getInvoiceTable(Order $order, Array $elementToDisplay = ['getTotal' => 'true', 'getVat' => 'false']) { return 'table'; } }
Ensuite dans mon template Twig :
J'arrive à récuperer ma valeur de retour (table).
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 <h1>{{ getInvoiceTable(order, [{ 'getTotal' : 'true', 'getVat' : 'false' }]) }}</h1>
Y a t'il une méthode plus simple pour ce que je veux faire ou je continue avec ma fonction Twig ? Si je continue, comment je procède pour afficher mon tableau ?
Merci
Partager