A dissolution–recrystallization-based structural transition from a porous solid to a heterometallic solid via the encapsulation of M2+ cations is observed, showing that the structural topology can be pre-determined by the ligand itself. Additionally, anions can also be ion-exchanged into solids, leading to tunable thermochromic responses.