/** * Generates (and writes) a file based on a certain template * * @param string $template The path to the template * @param array $variables The variables to assign to the template * @return string The generated snippet */ public static function generateSnippet($template, $variables = null) { // get the content of the file $content = Model::readFile(BACKEND_MODULES_PATH . '/ModuleMaker/Layout/Templates/' . $template); // replace the variables if ($variables && is_array($variables) && !empty($variables)) { foreach ($variables as $key => $value) { if (!is_array($value)) { $content = str_replace('{$' . $key . '}', $value, $content); } } } return $content; }