Hi
I use smarty template engine in my project.
I want to create a php function to convert smarty template engine to javascript like this:
public function text2JavaScript($file, $var)
{
$getFile = $GLOBALS['template']->fetch($file);
$exp = explode("\n", $getFile);
$getFileContent = 'var '.$var.' = "";'."\n";
foreach ($exp as $e)
{
$setE = str_replace('"', '\"', $e);
$getFileContent .= $var.' += "'.$setE.'";';
}
return $getFileContent;
}
This code is working! But it's contains an error in the output:
Example:
var loginForm = "";
loginForm += "
";loginForm += "<script type=\"text/javascript\">
";loginForm += "
";loginForm += "function viewLoginForm()
";loginForm += "{
";loginForm += " $('#ajaxLoginContent').modal();
";loginForm += "}
";
My question is: How can i add "\n" after the end of the statement? like this:
var loginForm = "";
loginForm += "";
loginForm += "<script type=\"text/javascript\">";
loginForm += "";
loginForm += "function viewLoginForm()";
loginForm += "{";
loginForm += " $('#ajaxLoginContent').modal();";
loginForm += "}";
Anyone can help? 🙂