Heat the olive oil in a medium nonstick pan or large heavy-based pot.
Slice the onions and then add them to the oil with the garlic and thyme and cook for about 30 – 35 minutes over low to medium heat. Stir frequently and allow the onions to turn a golden caramel colour but not brown. About 5 minutes before they are finished cooking, add the chopped anchovies and stir until they break down into the mix. The onions should have an almost jam-like sticky texture. Set aside (this can be made in advance).
While the onions are cooking, add the ricotta, goats’ cheese, garlic and herbs to a small food processor and whip until you get a smooth soft cream cheese consistency.
Half an hour before you are ready to serve, preheat the oven to 180C / 350F.
Place the pastry on a baking tray lined with baking paper. Score the pastry about 1cm in from the edge making sure you only cut about halfway through. Spread 2/3 of the cooled caramelized onion mixture over the base within the border. Then spread the whipped ricotta and goats’ cheese over that. Dot over the remaining onion mixture and bake for 20 – 25 minutes until the edges are golden brown.
Scatter over the toasted pine nuts, fresh rocket and balsamic vinegar (optional). Serve with a leafy salad dressed with a vinaigrette dressing.