If you include a reference to an external source, it would be super great if you could provide a link to that resource, so we don’t have to start googling first. Thank you.
Where do you define $pages?
I don’t quite see why the error should appear in the panel? This has nothing to do with the Panel.
I define $pages in the template before I pass it over to the snippet.
The error occurs in the panel, because the panel tries to display the informations produced by the snippet. So, it’s not a topic of the panel, that’s right. I just have an error in passing the variable to the snippet, I think; and I don’t find the cue…
The target is to display some subpage of $pages->visible() out of the snippet…
When you use snippets to preview the entries’ content, the builder field will automatically pass the data from the field to the $data variable of the field. There is no way to add additional variables from within the panel.
Maybe it would be a solution for you to have the logic to create $pages inside the snippet?
Add an if clause in the snippet, to check if it is being displayed in the ‘home’ template and if not, it means it’s being displayed in the kirby panel.