#740572 by a_c_m: Fixed and uses l() instead of custom building the links in the TPL, as well as moving that logic to the pre-process function.