I was thinking of doing it with Javascript, but I first want to know for sure if it isn't possible with Twig/Symfony itself?
First idea is always the best one ;) Twig is a template language and is parsed server side. The idea of yours to just hide the other field with javascript
is a good way to handle these things.
But there is an important thing to note! I guess only one of the fields url
and file
has to be filled out. With a plain Javascript solution always both of the fields will be send to your app. Therefore Symfony2 provides form events. There is a whole chapter in the cookbook about them.