'Valid template ID required'], 'Invalid request' ); } // Cast to integer for safety $templateId = (int)$templateId; // Get template $conn = Database::getConnection(); $templateModel = new TemplateModel($conn); $template = $templateModel->getTemplateById($templateId); if ($template) { echo json_encode(['success' => true, 'template' => $template]); } else { ErrorHandler::sendNotFoundError('Template not found'); } } catch (Exception $e) { ErrorHandler::log($e->getMessage(), E_ERROR); ErrorHandler::sendErrorResponse('Failed to retrieve template', 500, $e); }