Fragment¶
Base class: Part
Fragment is a class used to build small HTML fragments that plug into iommi’s structure.
h1 = Fragment(children__text='Tony', tag='h1')
# There is also a shorthand version that is identical to the above:
h1 = Fragment('Tony', tag='h1')
It’s easiest to use via the html builder:
h1 = html.h1('Tony')
Fragments are useful because attrs, template and tag are evaluated, so if
you have a Page with a fragment in it you can configure it later:
class MyPage(Page):
header = html.h1(
'Hi!',
attrs__class__staff=
lambda request, **_: request.user.is_staff,
)
Rendering a MyPage will result in a <h1>, but if you do
MyPage(parts__header__tag='h2') it will be rendered with a <h2>.
Refinable members¶
after (evaluated)¶
Type: Union[int, str]
See after
assets¶
Type: Namespace
See assets
attrs (evaluated)¶
Type: Attrs
See attributes
children¶
endpoints¶
Type: Namespace
See endpoints
extra¶
Type: Dict[str, Any]
See extra
extra_evaluated¶
Type: Dict[str, Any]
See extra
extra_params¶
See extra_params
include (evaluated)¶
Type: bool
See include
iommi_style¶
Type: str
See iommi_style
tag (evaluated)¶
See tag
template (evaluated)¶
Type: Union[str, Template]
See template