| 73 | All directives can be applied as attributes, and some can also be used as elements. The `if` directives for conditionals, for example, can be used in both ways: |
| 74 | |
| 75 | {{{ |
| 76 | <html xmlns="http://www.w3.org/1999/xhtml" |
| 77 | xmlns:py="http://markup.edgewall.org/" |
| 78 | lang="en"> |
| 79 | ... |
| 80 | <div py:if="foo"> |
| 81 | <p>Bar</p> |
| 82 | </div> |
| 83 | ... |
| 84 | </html> |
| 85 | }}} |
| 86 | |
| 87 | This is basically equivalent to the following: |
| 88 | |
| 89 | {{{ |
| 90 | <html xmlns="http://www.w3.org/1999/xhtml" |
| 91 | xmlns:py="http://markup.edgewall.org/" |
| 92 | lang="en"> |
| 93 | ... |
| 94 | <py:if test="foo"> |
| 95 | <div> |
| 96 | <p>Bar</p> |
| 97 | </div> |
| 98 | </py:if> |
| 99 | ... |
| 100 | </html> |
| 101 | }}} |
| 102 | |
| 103 | The rationale behind the second form is that directives not always map naturally to elements in the template. In such cases, the [wiki:MarkupTemplates#pystrip py:strip] directive can be used to strip off the unwanted element, or the directive can simply be used as an element. |
| 104 | |