• 991 views
  • 0 comments
  • loading...

generate custom XML tags

Sometimes you need to generate custom XML tags. web2py provides TAG, a universal tag generator.

Arguments "a", "b", and "d" are automatically escaped; use the XML helper to suppress this behavior. Using TAG you can generate HTML/XML tags not already provided by the API. TAGs can be nested, and are serialized with str(). An equivalent syntax is:


If the TAG object is created with an empty name, it can be used to concatenate multiple strings and HTML helpers together without inserting them into a surrounding tag, but this use is deprecated. Use the CAT helper instead.

Self-closing tags can be generated with the TAG helper. The tag name must end with a "/".

Notice that TAG is an object, and TAG.name or TAG['name'] is a function that returns a temporary helper class.














# Example 1

{{=TAG.name('a', 'b', _c='d')}}

<name c="d">ab</name>

# Example 2
{{=TAG['name']('a', 'b', c='d')}}
{{=TAG['link/'](_href='http://web2py.com')}}

<link ref="http://web2py.com"/>


loading...

Sources / Reference

" Web2py Book - Chapter 5" is licensed under Creative Common License BY-NC-ND 3.0


Comments

loading...

Powered by
Web2py

Hosted on
www.pythonanywhere.com
(affiliated link)