as_tag

bootlace.util.as_tag(item: Taggable | dom_tag | str | Iterable[Taggable | dom_tag]) dom_tag[source]

Convert an item to a dominate tag.

bootlace uses dominate to render HTML. To do this, objects implement the Taggable protocol, providing a __tag__ dunder method. This method will also accept regular dominate tags, strings, and iterables of Taggable objects. It will try to always return a dominate tag.

To render taggable objects in a template, use render(), a convenience function that will convert the object to a dominate tag and then render it to a Markup object for use in a template.

Handling notes

When a string is passed in, it will be wrapped with dominate.util.text to render a literal string as a tag. When an iterable of taggable items is passed, it is returned as a dominate.util.container, which will render the tags in sequence.

Unknown types are displayed using their string representation (by calling str on them), along with a comment in the rendered HTML and a Bootlace warning emitted.

Arguments

param item:

The item to convert to dominate tags.

returns:

A dominate tag.