Raistlin clutched at him. “Help me find the spellbook!” he hissed. “Who cares about that?” Caramon roared, reaching for his brother. “I’ll get you out of here!” Raistlin’s mouth twisted so in fury and frustration that he could not speak. He dropped to his knees and began to search frantically through the pile of treasure. Caramon tried to draw him away, but Raistlin shoved him back with his frail hand.
Inevitably, your PCs are going to defeat an enemy inside an eldritch temple. And inevitably, that temple will start to collapse.
That’s when the PCs spy the treasure. (Or the area that they need to search – perhaps multiple times – to find the treasure.)
The DM should give the PCs all the information they need to make agonizing choices: what their chance of search success is, and the dangers of tarrying for an extra round or two to search.
I did this when my PCs fought Tiamat. They flew into Tiamat’s mouth and fought a pitched battle against one of her aspects on Tiamat’s beating heart. Tiamat offered knowledge to the wizard: a library containing every spell ever, if the wizard would waste actions during the battle to read them. The library was still there when Tiamat died and her body begain to collapse. The wizard resisted the temptation to search for books, but the ranger HAD to have one of Tiamat’s heads as a souvenir.