Zope Page Templates (ZPT) ========================= >>> from z3c.pt.testing import render_zpt TAL --- :: Namespace elements >>> print render_zpt("""\ ... ... Hello, world! ... """) Hello, world! tal:define, tal:attributes, tal:contents >>> print render_zpt("""\ ...
... ... Hello Universe! ... Hello Universe! ... ...
""")
abcghi Hello World! Hello World!
tal:repeat >>> print render_zpt("""\ ...
...

...
...

...
""")

- Item 0)
- Item 1)
- Item 2)
- Item 3)
- Item 4)

tal:repeat (repeat-variable) >>> print render_zpt("""\ ...
...

...
...

...
""")

- 0 True
- 1 False
- 2 True

tal:condition >>> print render_zpt("""\ ...
...
... Show me! ...
...
... Do not show me! ...
...
""")
Show me!
:: HTML comments >>> print render_zpt("""\ ...
... ... ... ...
""")
:: TAL elements with namespace prefix >>> print render_zpt("""\ ...
... ... ... ... True ...
""")
Hello World! Hello World! 0 1 2 True
tal:omit-tag >>> print render_zpt("""\ ...
...

No paragraph here.

...

No paragraph here either.

...

A paragraph here.

...
""")
No paragraph here. No paragraph here either.

A paragraph here.

:: Unicode with dynamic attributes and content >>> print render_zpt("""\ ...
... ... ... ... ...
""")
<br /> La Peña
:: Using the "path:" expression >>> class Test(object): ... greeting = u'Hello' >>> print render_zpt("""\ ...
... ... ...
""", request=object(), ... test1={'greeting': u'Hello'}, test2=Test())
Hello Hello
:: Using the "string:" expression >>> print render_zpt("""\ ...
... ... ...
""", request=object(), greeting=u'Hello')
Hello, world!
:: Setting the default expression >>> print render_zpt("""\ ...
...
... ...
...
""", request=object(), test={'greeting': u'Hello'})
Hello
:: Using different expressions with try-except operator (|) >>> print render_zpt("""\ ...
... ...
... ... ... ... ...
... ... ... ... ... ...
""")
1 1 2 10
1 2 True 1
:: Using TAL pragmas "nocall" and "structure" >>> print render_zpt("""\ ...
... ... ...
""", request=object())
METAL ----- metal:define-macro, metal:use-macro >>> body = """\ ...
...
... Hello, ${name}! ...
...
...
...
...
""" >>> from z3c.pt.testing import MockTemplate >>> from z3c.pt.zpt import ZopePageTemplateParser >>> template = MockTemplate(body, ZopePageTemplateParser) >>> print render_zpt(body, template=template)
Hello, world!
metal:define-slot, metal:fill-slot >>> body = """\ ...
...
... Hello, stranger! ...
...
... earth! ...
...
...
... earth! ...
...
...
... ...
...
... dummy! ...
...
""" >>> from z3c.pt.testing import MockTemplate >>> template = MockTemplate(body, ZopePageTemplateParser) >>> print render_zpt(body, template=template)
Hello, earth!
Hello, earth!
Hello, stranger!
Hello, stranger!