Peel and finely slice the garlic, pick and finely chop the rosemary leaves, discarding the stalks. Peel and slice the onions, and slice the aubergines and courgettes lengthways, roughly 5mm thick.
Peel and cut the squash into 5mm slices, then place on an oven tray, season and drizzle over 3 tablespoons of oil. Roast on the top shelf of the oven for 35 minutes, or until soft, adding the garlic and rosemary after 20 minutes.
Put the whole peppers on a second tray and place on the lower shelf of the oven for 35 minutes, or until blackened. Tip them into a bowl, cover with clingfilm and set aside for 10 minutes.
Peel and discard the skins of the peppers, deseed, then slice the flesh into large pieces. Season, then place in a colander to drain.
Heat 2 tablespoons of oil in a large pan over a medium heat and sweat the onions for 10 to 12 minutes, or until just caramelised. Stir in the balsamic and sugar and cook for another 5 minutes.
Place a griddle pan over a medium-high heat. Brush the aubergine and courgette slices with oil and place on the hot griddle for 5 minutes, until soft and lightly charred (do this in batches). Turn and season them halfway through, then transfer to a plate. Set aside.
Fill and boil the kettle. Put the spinach in a colander and pour over the boiling water to wilt it. Let it cool, then squeeze it dry, chop it up and pop it into a bowl.
Add the ricotta to the spinach, then finely grate in the lemon zest and half the Parmesan. Season, stir to combine and set aside.
Reduce the oven temperature to 180ºC/350°F/gas 4 and grease and flour a 23cm spring-form cake tin.
On a floured surface, roll out 420g of the pastry, so it fits the base and sides of the tin. Carefully press the pastry into the tin, leaving a little overhang, and trim off any excess.
Pick the basil leaves. Sprinkle half the basil and half of the remaining Parmesan over the pastry base, then layer up the veg. Begin with the courgettes and aubergines followed by a layer of the peppers, then the spinach. Spoon over the squash and onions, dot over pieces of the goat’s cheese, then scatter on the rest of the basil and Parmesan.
Beat and brush the egg around the edge of the pie. Roll out the rest of the pastry, place it on top and crimp the edges with your fingers to seal. Poke a hole in the pastry top and brush with the beaten egg.
Bake the pie in the oven for 45 minutes, or until golden, covering the top with kitchen foil for the last 10 minutes if it looks too dark.
Leave the pie to cool in the tin on a wire rack for 10 minutes, then take it out of the tin to cool completely. Serve hot or cold.