Tunable photochemical properties of a covalently anchored and spatially confined organic polymer in a layered compound.