How could one make a template that based on some condition renders itself again?
You can just re-call the
You can change the template on the fly:
Magento does this by abandoning the template approach and instead concatenating HTML in a block. You can see this in /app/code/core/Mage/Page/Block/Html/Topmenu.php:
I recommend not handling it in the block, though. So you could easily create a function in the view and call it:
Which outputs markup as you'd expect: