We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to create HTML view without using Phalcon View Helper

Can i use the normal standard HTML building blocks to create form, page layout and others without using the Phalcon View Helper? What am trying to do is have total control over the view page layout

Yes, but why you want to do it ? Phalcon view service solves many things.



85.5k
edited Aug '16

for phalcon 3+

return "<html><body> etc </body></html>"; //in controller

or simply dont use layout, just views.

You can use

$view = new View();
$view->registerEngines(['.phtml' => 'Phalcon\Mvc\View\Engine\Php']);

inside you can type as much html as you want.

In volt you can type as much html as you want too :D

edited Aug '16

Thanks Izo, do you mean i can add html to my .phtml view file?

I feel i should be able to write plain html using the normal approach to creating html with php in view folder without using View Helper.....just my own custom HTML



145.0k
Accepted
answer

But you can do it, you don't even need to use view service anywhere. Just set it and it's basically it. Create volt/phtml files and that's it. You can just normally add HTML CODE to your volt files, for example volt file from my project:

<!DOCTYPE html>
<!--[if IE 8]>
<html lang="pl" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]>
<html lang="pl" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="pl">
<!--<![endif]-->
<!-- BEGIN HEAD -->

<head>
    <meta charset="utf-8"/>
    <title>Suzuki | Panel Adminsitracyjny</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1" name="viewport"/>
    <meta content="" name="description"/>
    <meta content="" name="author"/>
    {% if request.hasQuery("flush") %}
        {{ assets.outputCss("css") }}
    {% else %}
        <link rel=stylesheet type="text/css" href="/css/dist/backend.css"/>
    {% endif %}
    <link rel="shortcut icon" href="favicon.ico"/>
    {% if request.hasQuery("flush") %}
        {{ assets.outputJs("js") }}
    {% else %}
        <script src="/js/dist/backend.js"></script>
    {% endif %}
</head>
<!-- END HEAD -->

<body class="page-header-fixed page-sidebar-closed-hide-logo page-md" ng-app="suzuki">
<!-- BEGIN CONTAINER -->
<div class="wrapper">
    <!-- BEGIN HEADER -->
    <header class="page-header">
        <nav class="navbar mega-menu" role="navigation">
            <div class="container-fluid">
                <div class="clearfix navbar-fixed-top">
                    <!-- Brand and toggle get grouped for better mobile display -->
                    <button type="button" class="navbar-toggle" data-toggle="collapse"
                            data-target=".navbar-responsive-collapse">
                        <span class="sr-only">Toggle navigation</span>
                                <span class="toggle-icon">
                                    <span class="icon-bar"></span>
                                    <span class="icon-bar"></span>
                                    <span class="icon-bar"></span>
                                </span>
                    </button>
                    <!-- End Toggle Button -->
                    <!-- BEGIN LOGO -->
                    <a id="index" class="page-logo" href="index.html">
                        <img src="../assets/layouts/layout5/img/logo.png" alt="Logo"> </a>
                    <!-- END LOGO -->
                    <!-- BEGIN TOPBAR HEADER -->
                    {% include 'panel/header.volt' %}
                    <!-- END TOPBAR HEADER -->
                </div>
                <!-- BEGIN HEADER MENU -->
                {% include 'panel/menu.volt' %}
                <!-- END HEADER MENU -->
            </div>
            <!--/container-->
        </nav>
    </header>
    <!-- END HEADER -->
    <div class="container-fluid">
        {% block content %}{% endblock %}
        <!-- BEGIN FOOTER -->
        {% include 'panel/footer.volt' %}
        <!-- END FOOTER -->
    </div>
</div>
<!-- END CONTAINER -->
<!-- BEGIN QUICK SIDEBAR -->
{% include 'panel/quick-sidebar.volt' %}
<!-- END QUICK SIDEBAR -->

</body>

</html>

I feel i should be able to write plain html using the normal approach to creating html with php in view folder without using View Helper.....just my own custom HTML