Darn, that one I guess is a big oversight on my side.
The original idea was to actually extract the parts of the template dealing with attachments and put them into different functions, but I didn't track the idea and lost track of it... :-[
Sorry about that.
As a quick workaround, I would change:
', $context['attachments']['can']['post'] ?
to:
', isset($context['attachments']) && $context['attachments']['can']['post'] ?
and:
if ($context['attachments']['can']['post'] || !empty($context['attachments']['current']))
to:
if (isset($context['attachments']) && $context['attachments']['can']['post'] || !empty($context['attachments']['current']))
Tracked at https://github.com/elkarte/Elkarte/issues/3015