Dynamic layouts
In markup oriented eno usecases we often deal with sections that contain dynamic layouts of content, meaning the quantity, order and type of elements is variable and we can not just statically query everything by key but instead we iterate and respond to what we find dynamically.
for element in document.elements():
if element.string_key() == 'foo':
# ...
The elements
accessor returns the ordered elements of a section as a list.
As every element can be asked for a key, we can safely use this to determine
further actions on an element.
for element in document.elements():
if element.yields_field():
value = element.to_field().required_string_value()
# ...
elif element.yields_list():
# ...
Not every element we encounter in a section has a value (fieldsets, lists and
sections don't), therefore we use the yields_\[element_type]()
methods to check for a
specific element type before we make any queries that require e.g. a field when
we expect different types.
Next page: Requiring all elements