I use phalconphp framework for my test project.
I have simple controller with following code:
$this->view->setVar('myData', $data);
Are there any tools in PhalconPHP to minify HTML code in view?
Thanks!
I use phalconphp framework for my test project.
I have simple controller with following code:
$this->view->setVar('myData', $data);
Are there any tools in PhalconPHP to minify HTML code in view?
Thanks!
At this point this is not yet possible built in. But have used this function to achieve the minify option.
function minifyHTML($content)
{
$start = strpos( $content, '[#strip#]');
if ($start > 0) {
$end = strpos($content, '[#endstrip#]');
$part = substr($content,$start, $end - $start + 12);
$content = str_replace($part,str_replace(array("\r", "\n", "\t" ,
'[#strip#]', '[#endstrip#]'), '' , $part) , $content);
if(strpos( $content, '[#strip#]') > 0)
$content = stripHTML($content);
}
return $content;
}
Then in your volt file use it like this. But make sure to use tabs as indents instead of spaces in your volt file. Also [#strip#] tags are not allowed to be nested.
<!DOCTYPE html>
<html lang="nl">
<head>[#strip#]
<meta charset="utf-8">
{% block head %}
{{ assets.outputCss() }}
{% endblock %}
<title>{% block title %}{% endblock %}</title>
[#endstrip#]</head>
<body>
{% block content %}
{% endblock %}
{% block script %}
[#strip#]{{ assets.outputJs() }}[#endstrip#]
{% endif %}
{% endblock %}
</body>
</html>
And finally use it on your handle()->getContent().
$application = new \Phalcon\Mvc\Application($di);
echo minifyHTML( $application->handle()->getContent());
CSS and JavaScript is minified by built-in functions as you can see here: http://docs.phalconphp.com/en/latest/reference/assets.html#minification-filtering
It seems as if there is no tool for minifying HTML because it's not common to do this. But consider writing your own "minify"-function. There is not much to do because line breaks have no impact in HTML code and you can remove them in your output with something like this:
str_replace(array("\r\n", "\r"), "", $output);
Additionally - if you don't use more than one whitespace in your content - you can remove tabs, linebreaks and whitespaces like this:
preg_replace("/\s+/", " ", $string);