| 20 | |
| 21 | Sometimes template creator will have to think about optimizations while creating template. For example in following code: |
| 22 | |
| 23 | {{{ |
| 24 | <a href="/edit/1" py:if="user.autorized()">[edit]</a> |
| 25 | <p>1111 11 11</p> |
| 26 | <a href="/edit/2" py:if="user.autorized()">[edit]</a> |
| 27 | <p>222 22 22 2</p> |
| 28 | <a href="/edit/3" py:if="user.autorized()">[edit]</a> |
| 29 | <p>333 33333 33 333</p> |
| 30 | }}} |
| 31 | The variable here is user. Creating pre-render dict user -> pre-rendered paragraph wont't help a lot, because there will be a lot of users. But this code can be also written as: |
| 32 | {{{ |
| 33 | <py:with vars="a = user.authorized()"> |
| 34 | <a href="/edit/1" py:if="a">[edit]</a> |
| 35 | <p>1111 11 11</p> |
| 36 | <a href="/edit/2" py:if="a">[edit]</a> |
| 37 | <p>222 22 22 2</p> |
| 38 | <a href="/edit/3" py:if="a">[edit]</a> |
| 39 | <p>333 33333 33 333</p> |
| 40 | </py:with> |
| 41 | }}} |
| 42 | Now fragment depends only on variable "a", which can be only True or False, which gives optimization possibilities. |