Extend templates through the hook file
I see the name of the function is attachments and the file name is attachment. Maybe, you just need to remove an extra "s" from the function name? 

function smarty_function_attachment(array $params, Smarty_Internal_Template $template) {
  .
  .
}