The Twig Book
Total Page:16
File Type:pdf, Size:1020Kb
The Twig Book generated on January 15, 2014 The Twig Book This work is licensed under the “Attribution-Share Alike 3.0 Unported” license (http://creativecommons.org/ licenses/by-sa/3.0/). You are free to share (to copy, distribute and transmit the work), and to remix (to adapt the work) under the following conditions: • Attribution: You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work). • Share Alike: If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license. For any reuse or distribution, you must make clear to others the license terms of this work. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor SensioLabs shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. Contents at a Glance Introduction .......................................................................................................................................5 Twig for Template Designers...............................................................................................................7 Twig for Developers..........................................................................................................................20 Extending Twig ................................................................................................................................29 Twig Internals...................................................................................................................................43 Recipes .............................................................................................................................................46 Coding Standards .............................................................................................................................55 autoescape ......................................................................................................................................57 block ...............................................................................................................................................59 filter..............................................................................................................................................60 do.....................................................................................................................................................61 embed ...............................................................................................................................................62 extends............................................................................................................................................65 flush ...............................................................................................................................................70 for ...................................................................................................................................................71 from .................................................................................................................................................75 if.....................................................................................................................................................76 import..............................................................................................................................................77 include............................................................................................................................................79 macro ...............................................................................................................................................81 sandbox............................................................................................................................................83 set ...................................................................................................................................................84 spaceless ........................................................................................................................................86 use ...................................................................................................................................................87 verbatim..........................................................................................................................................90 abs ...................................................................................................................................................91 batch ...............................................................................................................................................92 capitalize ......................................................................................................................................93 convert_encoding ...........................................................................................................................94 date .................................................................................................................................................95 date_modify.....................................................................................................................................97 default............................................................................................................................................98 escape..............................................................................................................................................99 first .............................................................................................................................................101 format............................................................................................................................................102 PDF brought to you by Contents at a Glance | iii generated on January 15, 2014 join ...............................................................................................................................................103 json_encode...................................................................................................................................104 keys ...............................................................................................................................................105 last ...............................................................................................................................................106 length............................................................................................................................................107 lower .............................................................................................................................................108 nl2br .............................................................................................................................................109 number_format...............................................................................................................................110 merge .............................................................................................................................................111 upper .............................................................................................................................................112 raw .................................................................................................................................................113 replace..........................................................................................................................................114 reverse..........................................................................................................................................115 round .............................................................................................................................................117 slice .............................................................................................................................................118 sort ...............................................................................................................................................120 split .............................................................................................................................................121 striptags ......................................................................................................................................123 title .............................................................................................................................................124 trim ...............................................................................................................................................125 url_encode ....................................................................................................................................126