1S,2S)-N-methyl-pseudoephedrine (MPS) was used as organic structure-directing agent (OSDA) for the synthesis of Mg-doped nanoporous aluminophosphates. This molecule displays a particular conformational behavior, where the presence of H-bond donor and acceptor groups provide a rigid conformational space with one asymmetric conformation preferentially occurring. MPS drives the crystallization of Mg-containing AFI materials. Characterization of these materials shows that the OSDA incorporate as protonated species, arranged as head-to-tail monomers. Combination of three-dimensional electron diffraction with high-resolution synchrotron powder X-ray diffraction allowed to locate both the Mg and the organic species. Interestingly, results showed that the spatial incorporation of Mg is driven by the hydroxyl groups of the organic cation through the development of H-bonds with negatively-charged MgO 4 tetrahedra. This work demonstrates that H-bond forming groups can be used to drive the spatial incorporation of low-valent dopants within zeolitic frameworks, a highly desired aim in order to control their catalytic activity and selectivity.