All extra_hosts does is add that line to the containers /etc/hosts file.
The example file is a community provided file that is many years old.
Can you explain more what you mean by "doesn't work"? What errors are you getting, what pages are you seeing? Is the problem that you can not resolve pihole.server.local or is the problem that you are not seeing the admin page but another page?
Oh sorry, I thought that file was an official one. I expected that adding the extra_hosts was all I needed to do to add these subdomains as DNS records.
After adding pihole.server.local to the DNS records of pi-hole I could reach the admin page and everything is working as expected. So if I need to manually enter the subdomains in pi-hole, do I also need to add them to the extra_hosts? Is pi-hole using these records?