Using !include
(which is a non-standard YAML extension for ESPHome) is possible to replicate widgets in different places. It has a limitation, as far as I can tell, that it can basically only be used to replace values or value/key pairs, not list entries, which is a problem when you want to append to a widget list. Something like this works, but isn’t ideal because the included widgets have to be wrapped in an obj since the include can only replace an entire widget list, not append to it.
page_template.yaml:
- image:
align: center
id: page${id}_background
src: left_img
on_click:
lvgl.page.next:
- label:
align: top_mid
id: page${id}_label
text: Nix
- label:
align: center
text: Page ${id}
top-level yaml:
pages:
- id: page_1
pad_all: 0
widgets:
- obj:
width: 100%
height: 100%
widgets: !include { file: page_template.yaml, vars: { id: 1 } }
- id: page_2
pad_all: 0
widgets:
- obj:
width: 100%
height: 100%
widgets: !include { file: page_template.yaml, vars: { id: 2 } }
So it may be just as easy to simply replicate the common widgets on each page, depending on how many there are.
The good news is that however they are defined, it’s easy to update all of them at once - you can update multiple widgets of the same kind at the same time with a single action:
- lvgl.label.update:
id: [page1_label, page2_label]
text:
format: "Value %d"
args: ['(int)((float)rand() / RAND_MAX * 100)']
- lvgl.image.update:
src: left_img
id: [page1_background, page2_background]
Personally for your use-case I would probably not use pages for the views that have common elements, instead layout the screen with with the common elements fixed in place, and a tabview or tileview widget for the variable part. That could either occupy the entire screen with the common stuff on top, or take up part of the screen.
Those widgets also have the benefit of responding to swipes which pages don’t.
You could still use pages below that if you have other views that don’t include the common elements of course, just using a single page for the stuff we’ve been discussing.