Molecular templates can be used in many different ways to control the outcome of chemical reactions. Here we present a new type of template-directed synthesis. We show that templates can be used as shadow masks: the shape of the template becomes imprinted on the product because reaction only occurs at sites not masked by the template. We demonstrate this effect by using oligopyridine templates to dictate the sites of demetallation when a magnesium porphyrin nanoring is treated with acid. Magnesium centers that are coordinated to the template are protected whereas uncoordinated magnesium centers are removed. After site-selective demetallation, the template can be removed and other cations, such as zinc(II) and copper(II), can be inserted into the free-base porphyrin centers. This strategy provides a simple route to a wide range of heterometallated porphyrin arrays.